1
是否有可能通过分布式测试执行在pytest中查找命令行参数?pytest命令行参数@ pytest.mark.parametrize
py.test -n 16 tests/tests_*****.py --env="TestEnvironemnt" --html=XYZ/Reports.html
os.sys.argv是给在我的代码“-c”,如果我执行我的pytest代码
是否有可能通过分布式测试执行在pytest中查找命令行参数?pytest命令行参数@ pytest.mark.parametrize
py.test -n 16 tests/tests_*****.py --env="TestEnvironemnt" --html=XYZ/Reports.html
os.sys.argv是给在我的代码“-c”,如果我执行我的pytest代码
的问题不是很清楚,但我想你想添加一个选项“ - -env“并读取它的值。
做到这一点的方法是:
#conftest.py
def pytest_addoption(parser):
parser.addoption('--env', action="store", dest="env", default="",
help="Define name of test environment")
#conftest.py
@pytest.fixture
def env_name(request):
return request.config.getoption('env')
的值
request.config.getoption('env')
#test.py
def test1(env_name):
print("Test Environment is: {}".format(env_name))
获得的价值,我不知道我是否正确地理解你的问题,但确实[这个例子](HTTP:/ /docs.pytest.org/en/latest/example/simple.html#pass-different-values-to-a-test-function-depending-on-command-line-options)回答它? –
上面的链接不适合我。但是,以下是:http://docs.pytest.org/en/latest/example/simple.html –