Skip to main content

Fast mutation testing for Python

Project description

irradiate

Fast mutation testing for Python, written in Rust.

Why

Mutation testing is slow. The bottleneck isn't generating mutants — it's running the test suite once per mutant. A typical pytest startup costs 200-500ms, and with hundreds of mutants that adds up to minutes of pure overhead.

irradiate eliminates this by maintaining a pool of pre-warmed pytest workers. Pytest starts once, collects tests once, then forks a child process for each mutant. The result: mutation testing at 30-60 mutants/sec on real codebases.

How it works

  1. Parse Python source with tree-sitter (27 mutation operator categories, ~160+ distinct mutations)
  2. Generate trampolined mutants — each function gets an original, N mutated variants, and a runtime dispatcher
  3. Collect test coverage and timing in a single pytest run
  4. Fork a child process per mutant inside pre-warmed workers (no pytest restart)
  5. Report results as terminal output, JSON (Stryker schema v2), HTML, or GitHub Actions annotations

Install

pip install irradiate

Or build from source:

cargo build --release

Requires Python 3.10+ with pytest installed.

Usage

# Run mutation testing (auto-detects src/ and tests/)
irradiate run

# Only test functions changed since main
irradiate run --diff main

# Generate JSON report (Stryker mutation-testing-report-schema v2)
irradiate run --report json

# Generate self-contained HTML report
irradiate run --report html

# Fail CI if mutation score is below threshold
irradiate run --fail-under 80

# See cached results
irradiate results

# Show diff for a specific mutant
irradiate show module.x_func__irradiate_1

Configuration

Configure via [tool.irradiate] in pyproject.toml:

[tool.irradiate]
paths_to_mutate = "src"
tests_dir = "tests"
do_not_mutate = ["**/generated/*", "**/vendor/*"]
pytest_add_cli_args = ["-x", "--tb=short"]

All settings can be overridden via CLI flags. Run irradiate run --help for the full list.

Features

Mutation operators (27 categories)

Arithmetic, comparison, boolean, augmented assignment, unary, string mutation/emptying, number literals, lambda bodies, return values, assignments, default arguments, argument removal, method swaps, dict kwargs, decorator removal (planned), exception types, match/case removal, condition negation, condition replacement, statement deletion, keyword swap, loop mutation, ternary swap, slice index removal.

Functions can be excluded with # pragma: no mutate.

Execution model

  • Fork-per-mutant (default): Workers fork after pytest collection. Each mutant runs in an isolated child process — no state leakage between mutants, no pytest restart overhead.
  • --isolate: Full subprocess isolation. Slower but guaranteed clean for projects with complex test infrastructure.
  • --verify-survivors: After the main run, re-tests survived mutants in isolate mode to catch false negatives from warm-session state leakage.

Incremental mode (--diff)

Only mutate functions touched by a git diff. Uses git merge-base to compare against the divergence point, so --diff main does the right thing on feature branches.

Reporting

Caching

Content-addressable cache keyed on SHA-256 of function body + test IDs + operator. Survives rebases, branch switches, and touch — unlike mtime-based caches.

Decorator support

@property, @classmethod, and @staticmethod are handled natively via a descriptor-aware trampoline. Other decorated functions are skipped (source-patching fallback planned — see #13).

Performance tuning

  • --workers N: control parallelism (defaults to CPU count)
  • --timeout-multiplier N: scale per-mutant timeout (default 10x baseline)
  • --worker-recycle-after N: respawn workers after N mutants (auto-tuned)
  • --max-worker-memory N: recycle workers exceeding N MB RSS
  • --covered-only: skip mutants with no test coverage
  • --no-stats: skip coverage collection, test all mutants against all tests

How it compares to mutmut

mutmut irradiate
Speed pytest.main() per mutant (~200ms each) Fork-per-mutant — pytest starts once
Parser LibCST (Python) tree-sitter (Rust, parallel)
Operators ~20 categories 27 categories
Cache mtime-based Content-addressable (SHA-256)
Orchestration Python multiprocessing Rust + tokio async
Incremental --diff with merge-base
Reports Terminal only JSON, HTML, GitHub Actions annotations
Decorator support Skip all @property/@classmethod/@staticmethod handled
CI integration Manual --fail-under, GitHub annotations, step summary
Isolation Fork only Warm-session + --isolate + --verify-survivors

Acknowledgments

irradiate's trampoline architecture and mutation operator design are informed by mutmut. The naming convention is partially compatible with mutmut to ease migration.

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

irradiate-0.1.1.tar.gz (260.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

irradiate-0.1.1-py3-none-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

irradiate-0.1.1-py3-none-manylinux_2_28_aarch64.whl (1.9 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

irradiate-0.1.1-py3-none-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

irradiate-0.1.1-py3-none-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file irradiate-0.1.1.tar.gz.

File metadata

  • Download URL: irradiate-0.1.1.tar.gz
  • Upload date:
  • Size: 260.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for irradiate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 122e5b98a34f415b484f894fba16fa4d946dec23c5473f72b50ddfdbacdb6e57
MD5 790168a0694615e50ee479611eb11bc1
BLAKE2b-256 2949bb029dc296cc86cadfca4aef63c610335b762b5b3744e3581251e643cf81

See more details on using hashes here.

Provenance

The following attestation bundles were made for irradiate-0.1.1.tar.gz:

Publisher: release.yml on nwyin/irradiate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file irradiate-0.1.1-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for irradiate-0.1.1-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e63b09d991279b414d214c63fa8ee6e09056734e1e4025c15ecf7a6cbe600772
MD5 21e68c9e3238a3adfe781e98a2cadd14
BLAKE2b-256 0815bc1ba908401889aafa65b8d9bab28955d088c400a604624768fa011bfc8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for irradiate-0.1.1-py3-none-manylinux_2_28_x86_64.whl:

Publisher: release.yml on nwyin/irradiate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file irradiate-0.1.1-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for irradiate-0.1.1-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f95d44678a8901fbe335b118af5a02e304a17203c8a9f37361b6d76fc2fa0a05
MD5 5e58d8cd1f44c730948dd802d825e8d6
BLAKE2b-256 a457e763622dab9b4f6ba9683a95e0cda59c1c54222b451fe6ef512712863161

See more details on using hashes here.

Provenance

The following attestation bundles were made for irradiate-0.1.1-py3-none-manylinux_2_28_aarch64.whl:

Publisher: release.yml on nwyin/irradiate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file irradiate-0.1.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for irradiate-0.1.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00a855d4c32a396e5832e5ea96b047b3aaa69d543532ab12efe2cc30a4591100
MD5 e8a357ffeaa3f2ffc725551945dbc19f
BLAKE2b-256 087e97b491f7530cd54784e0695bfc00759da6d27502faadcd065888e2ef2d73

See more details on using hashes here.

Provenance

The following attestation bundles were made for irradiate-0.1.1-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on nwyin/irradiate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file irradiate-0.1.1-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for irradiate-0.1.1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b25e2dc704cfc53d5f1d28bffd000ec955859de90604761a5f86431476540dcd
MD5 194123a819297617106b6cce8f7f22d4
BLAKE2b-256 d94ce0405f93bc68bec5a93d36b7e35378a5c6a0081d5a56c6abb79c85255813

See more details on using hashes here.

Provenance

The following attestation bundles were made for irradiate-0.1.1-py3-none-macosx_10_12_x86_64.whl:

Publisher: release.yml on nwyin/irradiate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page