pytestmut¶
Find the bugs your tests would miss.
pytestmut makes small, deliberate mistakes in your code and runs your pytest suite against each one. Every mistake that slips through comes back with the test that would catch it.
$ pytestmut run
src/shop/pricing.py:8 cmp.boundary [7bf19b971895] in discount
- if amount > 100 and loyal:
+ if amount >= 100 and loyal:
Changing `>` -> `>=` at src/shop/pricing.py:8 in `discount` went unnoticed. Tests
that ran this code and still passed: tests/test_pricing.py::test_discount. No test
sits on the boundary of `>`. Add a case where both sides are equal and assert the
result; ...
Line coverage tells you which code your tests run. Mutation testing tells you which code your tests check.
Why pytestmut¶
-
Correct results first
A mutant only counts as caught when a test that normally passes fails with it active. Crashes, flaky tests and slow machines never count.
-
Safe to run anywhere
Your files are never modified. Test processes are contained, cleaned up and held to a memory budget, and credentials are kept out of their reach.
-
Fast enough for every day
Each mutant runs only the tests that reach it, in parallel, and verdicts are cached between runs.
-
Strict where it matters
Give critical code its own thresholds, mutation types and rules for exceptions.
-
Built for review
Every missed mutant says what changed, which tests ran it, and what test would catch it, for people and coding agents alike.
-
Fits your workflow
Terminal, pre-commit, CI,
pytest --mutate, or an HTML report in your docs site.
Find your way¶
- Getting started: from first run to every mutant caught
- Reading the results: statuses, scores and reports
- Choosing what to test: changed lines, specific tests, specific code
- Leaving code alone: built-in rules and skip comments
- Strict rules for critical code: per-area thresholds
- Pre-commit: check changes before each commit
- CI/CD: gate pipelines, publish reports
- Coding agents: let an agent review its own tests
- Reports in your docs site: MkDocs and Read the Docs
- Speed and memory: workers, budgets, timeouts
- Troubleshooting: every error message, explained
- Command line · Configuration · Operators
Requirements¶
- Python 3.10 or newer, pytest 8 or newer.
- Your project's tests must import your source files directly: an editable
install (
uv sync,pip install -e .) or a layout pytest can import, such aspythonpath = ["src"]. - Linux, macOS and Windows, with Python 3.10 to 3.14: the full test suite runs on each in CI.