Reputation: 7511
Reading http://doc.pytest.org/en/latest/example/markers.html I see the example of including or excluding certain python tests based on a mark.
Including:
pytest -v -m webtest
Excluding:
pytest -v -m "not webtest"
What if I would like to specify several marks for both include and exclude?
Upvotes: 22
Views: 12636
Reputation: 66421
Use and
/or
to combine multiple markers, same as for -k
selector. Example test suite:
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
Selecting all tests marked with foo
and not marked with bar
$ pytest -q --collect-only -m "foo and not bar"
test_mod.py::test_spam
test_mod.py::test_spam2
Selecting all tests marked neither with foo
nor with bar
$ pytest -q --collect-only -m "not foo and not bar"
test_mod.py::test_bacon
Selecting tests that are marked with any of 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
Upvotes: 31