fermut¶
Coverage tells you which lines your tests executed. It can't tell you whether your tests would notice if those lines were wrong.
A test that calls a function and asserts nothing produces 100% line coverage and zero behavioral guarantees. Mutation testing closes that gap: perturb your code in small, deliberate ways, re-run the tests, and report which perturbations slipped past. Each surviving perturbation is a named, located, reproducible hole in your test suite.
fermut is mutation testing built to be fast enough to actually run.
The mutator is native Rust; per-test coverage runs only the tests
that touch each mutant; mutants run in forks of one pytest that has
already imported your suite (schemata); the type-aware ty
pre-filter discards type-invalid mutants before they cost a test run;
content-hash caching means re-runs only pay for what changed. The
test runner stays the one your team already trusts — pytest,
rstest or unittest.
New to mutation testing? Start with First steps for a five-minute local run, or Mutation testing concepts for the "why bother" pitch in depth. Hit unfamiliar jargon? The Glossary is a one-page lookup.
Highlights¶
- Fast. Native-Rust mutator +
typre-filter throws away type-invalid mutants before they cost a pytest run. - Deterministic. Pinnable Hypothesis seed, content-hash result cache, deterministic sampling. Same commit → same survivors, given a pinned seed and a stable test environment.
- CI-ready.
--diff-only(only mutate changed lines),--coverage(per-test selection),--shard(matrix parallelism), sticky PR comments (one comment that updates in place on re-runs, not a stack), JUnit/JSON/HTML/Markdown reports. - Agent-friendly. Stable JSON shapes, score-delta trend log, cache hits that survive across iterations. See Coding agents.
- Curated profiles.
pr-gate,nightly,local,library— one flag and you have a sensible config. - Tracks itself.
.fermut/history.jsonl+fermut trendrender the score history as a sparkline.
Install¶
# Prebuilt wheel from PyPI (no Rust required):
uv tool install fermut
# Or build from source (requires Rust stable):
cargo install --git https://github.com/KovantAI/fermut --locked
Full prereqs (Python ≥ 3.10, pytest, coverage, pytest-cov, ty) and venv layout in Installation.
Why fermut over mutmut or cosmic-ray?¶
Both are good tools. fermut exists because mutation testing has been stuck on "interesting but too slow for CI" for a decade. The wins:
- Mutate in Rust, test in Python. The hot loop (parse, mutate, splice, fork) is native code; the test runner stays the one your team already trusts.
- Collect once, fork per mutant. Schemata builds every function-body mutant into one copy of your code; each mutant runs in a fork of a pytest that already imported and collected the suite, instead of paying pytest startup per mutant. 1.5–3.9× faster end to end on most suites tested — see Schemata.
- Type-aware pre-filter.
tydiscards type-invalid mutants before they cost a test run: about 30–40% of covered mutants across 9 benchmarked libraries — see benchmarks. - Content-hash cache. Re-running on the same commit re-uses prior verdicts. PR re-runs cost the diff, not the whole sweep.
For the full comparison, see Landscape.
First run¶
fermut init walks up to the project root, detects the layout, and
writes a fermut.toml. Run it bare — auto-detection picks a
profile based on project size:
cd path/to/your/project
fermut init
fermut baseline # environment check + coverage + sampled score
fermut run src/ --tests tests/
fermut baseline is the "where do I stand" step: it runs
doctor, builds per-test coverage, and
prints line coverage next to a sampled mutation score and the files
with the most survivors. See
fermut baseline.
The coverage it builds is coverage.py's own .coverage database with
per-test contexts, which fermut run finds at the project root by
itself. After you change tests, fermut coverage refreshes it
incrementally. See Coverage for the details.
Expected output — a line per survivor/timeout, then a one-line summary:
SURVIVED src/auth.py:42@1187 [boundary-shift] `age >= 18` → `age > 18`
152 mutants — killed: 140, survived: 8, timeout: 1, skipped: 3 (coverage 3), equivalent: 0, errored: 0 | score: 94.6%
detected = killed + timeout (here 141 / 149 = 94.6%). Skipped, errored and
equivalent mutants don't count either way.
See mutation score
for the formula.
Exit code is non-zero when any mutant survives — drop the command into CI as a gate.
Once the bare run feels right, switch to a named profile if your
use case matches one: pr-gate (PR CI gate), nightly (full
sweep), local (dev loop, 25% sample), library (reproducible
across contributors). fermut init --profile <name> --force
overwrites the auto-detected config. See
First steps for the full
walkthrough.
For coding agents¶
Driving fermut from Claude, Cursor, Aider, or your own scaffolding?
fermut run --json out.json emits a stable, versioned JSON contract;
mutant.id is the cache key and the selector for explain/suggest.
See Coding agents for the concrete cycle,
context-budget table, cache strategy, and explain --format json
integration.
Where next¶
-
Install, first run, feature tour, getting help.
-
Adopting fermut in a project, CI integrations, trends, coverage, filters.
-
What mutation testing measures, configuration model, caching, landscape of existing tools.
-
CLI, configuration keys, operators, benchmarks, policies, environment variables, shell completion, troubleshooting, internals.
Status¶
fermut is pre-1.0. The CLI, config schema, and JSON report shape may
change between 0.MINOR releases. See
Policies for the full contract.
License¶
Licensed under either of Apache License, Version 2.0 or MIT license at your option.