読むhttp://doc.pytest.org/en/latest/example/markers.htmlマークに基づいて特定の Python テストを含めるか除外する例を確認します。
含む:
pytest -v -m webtest
除外:
pytest -v -m "not webtest"
含めるマークと除外するマークの両方に複数のマークを指定したい場合はどうすればよいでしょうか?
ベストアンサー1
セレクターと同様に、複数のマーカーを組み合わせるにはand
/ を使用します。テスト スイートの例:or
-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
foo
または のマークが付いていないすべてのテストを選択するbar
$ pytest -q --collect-only -m "not foo and not bar"
test_mod.py::test_bacon
のいずれかのマークが付いたテストを選択するとfoo
、bar
$ 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