Scan your whole stack
Are you using pytest-leela?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v0.11.1
pytest-leela was last scanned on 23 Nov 2026 at version 0.11.1. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 0.11.1 LATEST | 23 Nov 2026 | No rules fired |
| 0.11.0 | 23 Nov 2026 | No rules fired |
| 0.10.0 | 22 Nov 2026 | No rules fired |
| 0.9.0 | 14 Oct 2026 | Not shown |
Findings for v0.11.1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 0.11.1; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
Type-aware mutation testing for Python.
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.
pip install pytest-leela
Run mutation testing on your whole test suite:
pytest --leela
After the normal pytest run, Leela reports its baseline check and prints a progress line before each mutant, with the active location and completed/runnable count. Pruned mutants are listed separately. Each completed mutant also gets a verdict and wall time covering the whole runner call, including any control and confirmation runs. Leela lists up to five slowest completed mutants at the end. The per-mutant elapsed time in the HTML report is unchanged.
When no --target is given, pytest-leela auto-discovers source files:
target/ or src/ directory (in that order) and mutates all .py files inside it.venv, build, dist, __pycache__, node_modules, .git, and similar non-source directories)Test files (test_*.py, *_test.py, conftest.py, tests.py) are always excluded from mutation.
Exclude patterns from [tool.pytest-leela] (see Configuration) are applied
after target discovery, so you can auto-discover src/ while still excluding specific paths.
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
+ to - on a str operand)sys.meta_path, zero
filesystem writes, fast loop--diff <ref> limits mutations to lines changed since that ref--max-cores N caps parallelism; --max-memory MB guards memory--leela-html generates an interactive single-file report with source viewer, survivor navigation, and test source overlay--leela-benchmark measures the speedup from each optimization layerConfigure pytest-leela in your pyproject.toml under [tool.pytest-leela]:
[tool.pytest-leela]
exclude = [
"*/migrations/*",
"manage.py",
"*/conftest.py",
]
operators = [
"arithmetic",
"comparison",
"boolean",
"return",
]
fail_on_error = true
excludeA list of glob patterns. Files whose path (relative to the project root) matches any pattern
are excluded from mutation. Uses fnmatch matching — * matches within a single directory,
*/migrations/* matches any migrations directory at any depth.
Default: [] (nothing excluded).
operatorsA list of operator category names controlling which mutation types are applied.
Use "all" as a shorthand to enable every category.
Default: ["arithmetic", "comparison", "boolean", "unary", "return"]
| Category | What it mutates | Default |
|---|---|---|
arithmetic |
+ - * / // % ** |
on |
comparison |
== != < <= > >= is in and negations |
on |
boolean |
and / or |
on |
unary |
unary - + not |
on |
return |
return values (True/False, None, literals, expressions) |
on |
bitwise |
& \| ^ << >> |
off |
augmented_assign |
+= -= *= etc. |
off |
ternary |
x if cond else y branch swaps |
off |
control_flow |
break / continue swaps |
off |
exception |
except handler broadening, body-to-raise |
off |
fail_on_errorWhether errored mutants fail the session (non-zero exit). Default: true.
See Mutant statuses. Set it to false only when you accept that some
mutants go untested, for example while fixing a known collection problem.
Each mutant ends in exactly one of three states:
| Status | Meaning | Counts toward the score |
|---|---|---|
| killed | A call-phase test failure or mutant timeout, or a setup/teardown/collection/import failure confirmed by a passing clean control and recurrence of the same failure under the mutant | yes |
| survived | Tests ran and all of them passed | yes |
| error | No trustworthy verdict: an inconclusive setup/teardown/collection/import failure, pytest crash, deliberate skip/exit, abnormal exit without a test failure, or zero tests run (for example everything skipped). An inconclusive error may have zero or positive call-phase tests_run |
no |
The mutation score is killed / (killed + survived). Errors are listed separately, with their
reason, in the terminal report, the HTML report and the JSON output, and they fail the session
unless fail_on_error = false. An error means leela could not tell whether your tests catch the
mutant, so it is reported as neither a kill nor a survival.
The initial clean baseline proves only that the selected tests passed before mutation. A setup, teardown, collection or import failure without a call-phase failure is initially inconclusive, even if earlier tests passed. Leela runs at most one clean unmutated control through the same selection and, only if that passes, one additional mutant confirmation. It counts a kill only when the actual phase, node, exception identity/message and meaningful visible chained cause recur. A failed control, different failure, surviving confirmation or insufficient exception evidence remains error, with the original and control/confirmation diagnostics. Ambient or flaky failures therefore do not automatically kill unrelated mutants. These are bounds on attempts, not a hard wall-clock execution limit or perfect proof against all nondeterminism.
This check preserves genuine mutation-caused target imports and test-module collection
failures, including module-level assertions such as assert calc.RATIO == 5; the killing
nodes name the files that failed to collect. A conftest's own check failing during
collection can also kill after this confirmation. Before the session starts, a failed
conftest import is eligible when the mutated target itself raised during import; a conftest's
own check without such a target import failure remains an error. A conftest that catches an
error and calls pytest.exit() or pytest.skip() remains an error, not a confirmed kill.
If a test caught the import error and the suite completed green, the mutant survived: no
test noticed it. If the mutant made the tests skip themselves (a module-level pytest.skip, a
skipif marker, or a conftest or test module that skips or calls pytest.exit() at import),
the mutant is an error: no test ran.
Known limits of these rules:
pytest --leela the outer session has
already imported it, so the clean baseline fails and the run aborts. When Engine.run is called
directly with use_coverage=False and a test directory, the baseline may be the first import
and pass. Later re-import failures also fail the clean per-mutant control: those mutants
are inconclusive errors, commonly with tests_run: 0, excluded from the score. Leela
does not make non-idempotent registration safe to repeat in-process.pytest.exit(), the inner run ends there and the
mutant is an error. Tests run only after collection, so no test failure is ever reported,
including a test that imports the target inside its body; nor is a sibling module's collection
failure that pytest would have reached after the exit. A module that already failed to
collect before the exit stops the run first (-x) can still kill after same-failure
confirmation.Before the first mutant, leela runs the selected tests once with no mutation applied, through
the same in-process path every mutant uses. If anything fails or errors there, the run aborts
with leela: aborted: tests do not pass with no mutation applied (...) and a non-zero exit,
and no mutants are scored. Without this check, a test that fails for an unrelated reason (a
fixture that cannot run in-process, a missing service) would score every mutant as killed.
pytest-django blocks database access for the whole session and only restores it at
unconfigure, after leela has run. Leela lifts that outer block for the duration of its run
(through pytest-django's own django_db_blocker.unblock()), so database tests in the inner
sessions can open connections as they do in a normal run.
Django model and admin modules are never reloaded between mutants (unless one is itself a
--target), and neither is any project module they reference. Re-executing them registers
models and admin classes a second time, which Django rejects, and re-importing a module they
reference would split class identity (a kept model subclassing the old copy of a reloaded
mixin). The trade-off: if a model or admin module imports a function from your target at
module level, calls through that reference run the unmutated code, which shows up as a
survivor, never as a fake kill.
Between mutants leela evicts the project's own modules so that mutated code is re-imported.
Installed packages are left loaded, even when the virtualenv sits inside the project directory
(uv's default .venv): anything under sys.prefix, sys.base_prefix, site.getsitepackages(),
site.getusersitepackages(), or a site-packages / dist-packages directory. Re-importing them
would break C extensions such as numpy, which CPython can load only once per process.
Add # leela: skip to suppress mutations on individual lines:
result = x + y # leela: skip
To skip an entire file, place the pragma on line 1:
# leela: skip
"""This module is excluded from mutation testing."""
def legacy_code():
...
The pragma is detected via Python's tokenize module, so it only matches actual comments —
not string literals or docstrings that happen to contain the text.
--leela-html report.html generates a single self-contained HTML file with no external dependencies.
What it shows:
Interactive features:
n next survivor, p previous, l list all, Esc closeUses the Catppuccin Mocha dark theme.
MIT
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.