如何为 pytest 命令指定多个标记

阅读 http://doc.pytest.org/en/latest/example/markers.html 我看到基于标记包含或排除某些python测试的示例。

包括:

pytest -v -m webtest

以外:

pytest -v -m "not webtest"

如果我想为包含和排除指定多个标记,该怎么办?


Smart猫小萌
浏览 224回答 1
1回答

一只萌萌小番薯

使用 / 组合多个标记,与选择器相同。示例测试套件:andor-kimport pytest@pytest.mark.foodef test_spam():    assert True@pytest.mark.foodef test_spam2():    assert True@pytest.mark.bardef test_eggs():    assert True@pytest.mark.foo@pytest.mark.bardef test_eggs2():    assert Truedef test_bacon():    assert True选择所有标记为“用”和“未用”标记的测试foobar$ pytest -q --collect-only -m "foo and not bar"test_mod.py::test_spamtest_mod.py::test_spam2选择所有既不标记为 with 也不标有foobar$ pytest -q --collect-only -m "not foo and not bar"test_mod.py::test_bacon选择标有 任一项的测试,foobar$ pytest -q --collect-only -m "foo or bar"test_mod.py::test_spamtest_mod.py::test_spam2test_mod.py::test_eggstest_mod.py::test_eggs2
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python