1 回答

TA贡献1795条经验 获得超7个赞
使用 / 组合多个标记,与选择器相同。示例测试套件:andor-k
import pytest
@pytest.mark.foo
def test_spam():
assert True
@pytest.mark.foo
def test_spam2():
assert True
@pytest.mark.bar
def test_eggs():
assert True
@pytest.mark.foo
@pytest.mark.bar
def test_eggs2():
assert True
def test_bacon():
assert True
选择所有标记为“用”和“未用”标记的测试foobar
$ pytest -q --collect-only -m "foo and not bar"
test_mod.py::test_spam
test_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_spam
test_mod.py::test_spam2
test_mod.py::test_eggs
test_mod.py::test_eggs2
添加回答
举报