Python 如何为pytest命令指定多个标记
在阅读本文时,我看到了基于标记包括或排除某些python测试的示例 包括:Python 如何为pytest命令指定多个标记,python,pytest,Python,Pytest,在阅读本文时,我看到了基于标记包括或排除某些python测试的示例 包括: pytest -v -m webtest 不包括: pytest -v -m "not webtest" 如果我想为include和exclude指定几个标记,该怎么办?使用和/或组合多个标记,与-k选择器相同。测试套件示例: import pytest @pytest.mark.foo def test_spam(): assert True @pytest.mark.foo def test_sp
pytest -v -m webtest
不包括:
pytest -v -m "not webtest"
如果我想为include和exclude指定几个标记,该怎么办?使用
和/或组合多个标记,与-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
选择标有foo
且未标有bar
$ pytest -q --collect-only -m "foo and not bar"
test_mod.py::test_spam
test_mod.py::test_spam2
$ pytest -q --collect-only -m "not foo and not bar"
test_mod.py::test_bacon
$ 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
选择既不标有foo
也不标有bar
$ pytest -q --collect-only -m "foo and not bar"
test_mod.py::test_spam
test_mod.py::test_spam2
$ pytest -q --collect-only -m "not foo and not bar"
test_mod.py::test_bacon
$ 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
选择标有foo
,bar
$ pytest -q --collect-only -m "foo and not bar"
test_mod.py::test_spam
test_mod.py::test_spam2
$ pytest -q --collect-only -m "not foo and not bar"
test_mod.py::test_bacon
$ 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