我有一个测试套件需要与多个后端一起运行。但这不是一个简单的参数化测试,因为它适用于整个套件(多个文件/模块)。我可以通过环境控制运行,但我想知道 py.test 是否有更清晰的方式来表达这一点。
也就是说,我正在寻找这样的东西:
py.test --set-mode ALPHA
然后在我的测试中我会读取这个值:
if py.test.mode == 'ALPHA':
Using pytest_addoption http://pytest.org/latest/plugins.html#_pytest.hookspec.pytest_addoption:
test_blah.py
def test_something(mode):
if mode == 'ALPHA':
assert True
else:
assert False
测试.py
import pytest
def pytest_addoption(parser):
parser.addoption("--set-mode", action="store", default="ALPHA",
help="ALPHA or BETA")
@pytest.fixture
def mode(request):
return request.config.getoption("--set-mode")
See 根据命令行选项将不同的值传递给测试函数 http://pytest.org/latest/example/simple.html#pass-different-values-to-a-test-function-depending-on-command-line-options.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)