我的 python 测试代码中有几个标记:
@pytest.mark.slowtest
@pytest.mark.webtest
@pytest.mark.stagingtest
我可以使用标记有选择地运行测试,例如pytest -m slowtest
我怎样才能运行未标记的测试而不求助于pytest -m "not (slowtest or webtest or stagingtest)"
?
正如你可以想象的,我们将来可能会使用其他标记......
我发现有用的另一个选项是使用pytest.ini
添加默认选项。我们明确地写出要跳过的标记。它需要将跳过的标记列表主流化pytest.ini
。换句话说,不是 100% OP 要求的,但这是我在寻找默认标记时发现的最好的问题。希望这可以帮助其他人。
来自docs https://docs.pytest.org/en/stable/reference.html#confval-addopts:
addopts
Add the specified OPTS to the set of command line arguments as if they had been specified by the user. Example: if you have this ini file content:
# content of pytest.ini
[pytest]
addopts = --maxfail=2 -rf # exit after 2 failures, report fail info
issuing pytest test_hello.py actually means:
pytest --maxfail=2 -rf test_hello.py
Default is to add no options.
我添加到 pytest.ini 中的内容
[pytest]
addopts = -m "not slow"
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
Using it
﮸$ grep 'mark.slow' tests/*.py | wc -l
3
$ pytest -s
======================================================= test session starts ========================================================
platform linux -- Python 3.8.2, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /tests, configfile: pytest.ini
collected 66 items / 3 deselected / 63 selected
../tests/test_app.py ...............................................................
================================================= 63 passed, 3 deselected in 8.70s =================================================
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)