Python 2.7 使用带参数的pytest运行Python脚本
我想使用Python 2.7 使用带参数的pytest运行Python脚本,python-2.7,pytest,Python 2.7,Pytest,我想使用pytest和同一脚本将使用的参数来执行下面的脚本 这是脚本名test.py: #!/usr/bin/env python import subprocess import os import sys import pytest a = sys.argv[3] # the argument that we need if len(a)== "0": sys.exit(1) def test_function(): assert a == "g" 在本例中,我想使用带有
pytest
和同一脚本将使用的参数来执行下面的脚本
这是脚本名test.py:
#!/usr/bin/env python
import subprocess
import os
import sys
import pytest
a = sys.argv[3] # the argument that we need
if len(a)== "0":
sys.exit(1)
def test_function():
assert a == "g"
在本例中,我想使用带有参数的pytest
运行此脚本
参数是:g
我已经尝试了命令
pytest-q test.py g
,但它不起作用。py.test扫描测试并运行所有测试。将相同的参数传递给每个测试文件是个坏主意
您可以使您的测试“自动运行”:
if __name__ == "__main__":
pytest.main("-vv")
# or pytest.main("-vv --cov --cov-report term-missing -s")
然后
chmod+x
手动运行文件:/test\u something.py
py.test扫描测试并运行所有测试。将相同的参数传递给每个测试文件是个坏主意
您可以使您的测试“自动运行”:
if __name__ == "__main__":
pytest.main("-vv")
# or pytest.main("-vv --cov --cov-report term-missing -s")
然后
chmod+x
您的文件并手动运行它:/test\u something.py
a=sys.argv[2]#如果您通过g
的pytest
将其视为一个文件参数,则我们需要---------------------->键入错误。为什么要这样传递测试参数?a=sys.argv[2]#如果传递g
则我们需要的参数----------------->键入错误pytest
将其视为文件参数。为什么要通过这样的测试参数?