Type-aware mutation testing for Python — fast, opinionated, pytest-native
Project description
pytest-leela
Type-aware mutation testing for Python.
What it does
pytest-leela runs mutation testing inside your existing pytest session. It injects AST mutations via import hooks (no temp files), maps each mutation to only the tests that cover that line, and uses type annotations to skip mutations that can't possibly fail your tests.
It's opinionated: we target latest Python, favour speed over configurability, and integrate with pytest without separate config files or runners. If that fits your workflow, great. MIT licensed — fork it if it doesn't.
Install
pip install pytest-leela
Quick Start
Run mutation testing on your whole test suite:
pytest --leela
Target specific modules (pass --target multiple times):
pytest --leela --target myapp/models.py --target myapp/views.py
Only mutate lines changed vs a branch:
pytest --leela --diff main
Limit CPU cores:
pytest --leela --max-cores 4
Cap memory usage:
pytest --leela --max-memory 4096
Combine flags:
pytest --leela --diff main --max-cores 4 --max-memory 4096
Generate an interactive HTML report:
pytest --leela --leela-html report.html
Benchmark optimization layers:
pytest --leela-benchmark
Features
- Type-aware mutation pruning — uses type annotations to skip mutations that can't possibly
trip your tests (e.g. won't swap
+to-on astroperand) - Per-test coverage mapping — each mutant runs only the tests that exercise its lines, not the whole suite
- In-process execution via import hooks — mutations applied via
sys.meta_path, zero filesystem writes, fast loop - Git diff mode —
--diff <ref>limits mutations to lines changed since that ref - Framework-aware — clears Django URL caches between mutants so view reloads work correctly
- Resource limits —
--max-cores Ncaps parallelism;--max-memory MBguards memory - HTML report —
--leela-htmlgenerates an interactive single-file report with source viewer, survivor navigation, and test source overlay - CI exit codes — exits non-zero when mutants survive, so CI pipelines fail on incomplete kill rates
- Benchmark mode —
--leela-benchmarkmeasures the speedup from each optimization layer
HTML Report
--leela-html report.html generates a single self-contained HTML file with no external dependencies.
What it shows:
- Overall mutation score badge
- Per-file breakdown with kill/survive/timeout counts
- Source code viewer with syntax highlighting
Interactive features:
- Click any line to see mutant details (original → mutated code, status, relevant tests)
- Survivor navigation overlay — keyboard shortcuts:
nnext survivor,pprevious,llist all,Escclose - Test source overlay — click any test name to see its source code
Uses the Catppuccin Mocha dark theme.
Requirements
- Python >= 3.12
- pytest >= 7.0
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_leela-0.2.0.tar.gz.
File metadata
- Download URL: pytest_leela-0.2.0.tar.gz
- Upload date:
- Size: 75.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9e047d2820acb771d1665c5723e58c64adfc41dc44dc87758f48d8fb27e1146
|
|
| MD5 |
d0e22f2158ae928ac72c948d678cd7d6
|
|
| BLAKE2b-256 |
14e6ee2debf3605959f75d3273dcc9899b141993c8df65f4720cd0337f3921ad
|
Provenance
The following attestation bundles were made for pytest_leela-0.2.0.tar.gz:
Publisher:
publish.yml on markng/pytest-leela
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_leela-0.2.0.tar.gz -
Subject digest:
c9e047d2820acb771d1665c5723e58c64adfc41dc44dc87758f48d8fb27e1146 - Sigstore transparency entry: 971630572
- Sigstore integration time:
-
Permalink:
markng/pytest-leela@7a07b7fe5ec8f6697b5c5d05d1859cdc95a5cc9d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/markng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7a07b7fe5ec8f6697b5c5d05d1859cdc95a5cc9d -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_leela-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pytest_leela-0.2.0-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e15cb719b78118f0012ef7e1ab4fe096bb1c55f9b08c1ac97ef3bbde13fae4a
|
|
| MD5 |
593501c84228c486d59a4c162beac26a
|
|
| BLAKE2b-256 |
13a5043de6ec3f7cfc4068027e2367825e333d453a5b93b443afffe34b055559
|
Provenance
The following attestation bundles were made for pytest_leela-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on markng/pytest-leela
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_leela-0.2.0-py3-none-any.whl -
Subject digest:
6e15cb719b78118f0012ef7e1ab4fe096bb1c55f9b08c1ac97ef3bbde13fae4a - Sigstore transparency entry: 971630588
- Sigstore integration time:
-
Permalink:
markng/pytest-leela@7a07b7fe5ec8f6697b5c5d05d1859cdc95a5cc9d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/markng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7a07b7fe5ec8f6697b5c5d05d1859cdc95a5cc9d -
Trigger Event:
release
-
Statement type: