Skip to content
Latchkey

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" -q

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →