[英]Pytest command line argument for @pytest.mark.parametrize
Is it possible to find command line arguments in pytest with distributed test execution? 是否可以通过分布式测试执行在pytest中找到命令行参数?
py.test -n 16 tests/tests_*****.py --env="TestEnvironemnt" --html=XYZ/Reports.html
os.sys.argv is giving as '-c' in my code , if am executing my pytest code 如果我正在执行我的pytest代码,os.sys.argv在我的代码中给出'-c'
The question is not very clear but I assume you want to add an option "--env" and read its value. 问题不是很清楚,但我假设你想添加一个选项“--env”并读取它的值。
The way to do it is: 做到这一点的方法是:
#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')
request.config.getoption('env')
获取值 #test.py
def test1(env_name):
print("Test Environment is: {}".format(env_name))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.