我的python测试代码中有几个标记:
@pytest.mark.slowtest
@pytest.mark.webtest
@pytest.mark.stagingtest
Run Code Online (Sandbox Code Playgroud)
例如,我能够使用标记选择性地运行测试 pytest -m slowtest
如何在不诉诸的情况下运行未标记的测试pytest -m "not (slowtest or webtest or stagingtest)"?
你可以想象,我们将来可能会使用其他标记......
我发现有用的另一个选项是用于pytest.ini添加默认选项。我们明确地写出要跳过的标记。它需要将 中跳过的标记列表主流化pytest.ini。换句话说,不是 100% OP 要求的,但这是我在寻找默认标记时发现的最好的问题。希望这可以帮助其他人。
来自文档:
\n\naddopts\n\n 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:\n\n # content of pytest.ini\n [pytest]\n addopts = --maxfail=2 -rf # exit after 2 failures, report fail info\n\n issuing pytest test_hello.py actually means:\n\n pytest --maxfail=2 -rf test_hello.py\n\n Default is to add no options.\n\nRun Code Online (Sandbox Code Playgroud)\n我添加到 pytest.ini 中的内容
\n[pytest]\naddopts = -m "not slow"\nmarkers =\n slow: marks tests as slow (deselect with \'-m "not slow"\')\nRun Code Online (Sandbox Code Playgroud)\n使用它
\n\naddopts\n\n 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:\n\n # content of pytest.ini\n [pytest]\n addopts = --maxfail=2 -rf # exit after 2 failures, report fail info\n\n issuing pytest test_hello.py actually means:\n\n pytest --maxfail=2 -rf test_hello.py\n\n Default is to add no options.\n\nRun Code Online (Sandbox Code Playgroud)\n
pytest -unmarked 插件旨在完成此任务。
PyPi 与项目主页的链接已损坏。这是正确的链接https://github.com/alyssabarela/pytest-unmarked
有关使用插件的更多信息,请访问https://docs.pytest.org/en/latest/plugins.html