Skip to content
Latchkey

pytest: Run Tests Command Reference for CI

The test runner at the center of most Python CI suites.

pytest discovers and runs tests, reporting failures with rich tracebacks. This page covers the flags and CI patterns you reach for when wiring it into a pipeline.

Common flags / usage

  • pytest tests/ -- run tests under a directory
  • -q, --quiet -- less verbose output for CI logs
  • -v -- verbose, one line per test
  • -ra -- summary of all non-passing outcomes at the end
  • --strict-markers -- error on unregistered markers
  • python -m pytest -- run via the interpreter so the project is importable

Example

shell
- run: pip install -e ".[test]"
- run: python -m pytest -q -ra --strict-markers

In CI

A bare "pytest" can fail collection with ModuleNotFoundError because the project root is not on sys.path. Run "python -m pytest" (which adds the working directory) or install the package with pip install -e . first.

Key takeaways

  • pytest discovers and runs tests with detailed failure output.
  • python -m pytest adds the working directory to sys.path, fixing import errors.
  • Use -q -ra in CI for compact logs with a clear failure summary.

Related guides

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