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?
To use markers, we have to import pytest module in the test file. We can define our own marker names to the tests and run the tests having those marker names. -m <markername> represents the marker name of the tests to be executed.
Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With