pytest Marks
Marks categorise tests for selective runs, skipping, and expected failures.
Marks categorise tests for selective runs, skipping, and expected failures.
import pytest
@pytest.mark.slow
def test_heavy_computation(): ...
@pytest.mark.skip(reason="feature not yet implemented")
def test_future_feature(): ...
@pytest.mark.skipif(sys.platform == "win32", reason="POSIX only")
def test_unix_paths(): ...
@pytest.mark.xfail(reason="known bug #123")
def test_known_issue(): ...
# Run only slow tests
# pytest -m slow
# Exclude slow tests
# pytest -m "not slow"
Register custom marks in pytest.ini to avoid PytestUnknownMarkWarning.