pytest -m: Select Tests by Marker Command Reference
Run tests tagged with a given marker.
pytest -m selects tests by marker expression -- tags applied with @pytest.mark. CI uses markers to separate fast tests from slow, integration, or flaky ones.
Common flags / usage
- -m "slow" -- run only tests marked slow
- -m "not slow" -- skip slow tests
- -m "integration and not flaky" -- combine markers
- register markers in pyproject.toml to avoid warnings under --strict-markers
Example
shell
# pyproject.toml
[tool.pytest.ini_options]
markers = ["slow: long-running tests", "integration: hits external services"]
# CI: fast lane excludes slow + integration
# python -m pytest -m "not slow and not integration" -qIn CI
Register every marker under [tool.pytest.ini_options] so --strict-markers does not fail the run on a typo. Run "-m not slow" on each push and the full suite (including slow/integration) on a schedule.
Key takeaways
- pytest -m selects tests by marker expressions with and/or/not.
- Register markers in pyproject.toml to satisfy --strict-markers.
- Markers cleanly separate fast CI lanes from slow/integration runs.
Related guides
pytest -k: Select Tests by Name Command ReferenceReference for pytest -k in CI: selecting tests by a name expression with and/or/not operators, sharding a sui…
pytest: Run Tests Command Reference for CIReference for pytest in CI: running the suite, useful flags, why python -m pytest fixes import errors, and a…
pytest --cov: Coverage Command Reference for CIReference for pytest --cov from pytest-cov in CI: measuring coverage, enforcing a threshold with --cov-fail-u…