Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 使用带参数的pytest运行Python脚本_Python 2.7_Pytest - Fatal编程技术网

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
将其视为文件参数。为什么要通过这样的测试参数?