Skip to main content

pytest-gremlins

Fast-first mutation testing for pytest. Speed that makes mutation testing practical for everyday TDD.

PyPI version Python versions CI codecov Documentation License: MIT

Let the gremlins loose. See which ones survive.


Key Features

  • Speed-First Architecture - Mutation switching eliminates file I/O and module reloads. Run gremlins in seconds, not hours.
  • Native pytest Integration - Zero configuration to start. Just add --gremlins to your pytest command.
  • Coverage-Guided Selection - Only runs tests that actually cover the mutated code. 10-100x fewer test executions in well-modularized codebases.
  • Incremental Caching - Results cached by content hash. Unchanged code skips re-testing entirely.
  • Parallel Execution - Distribute gremlins across CPU cores for linear speedup.

Quick Start

# Install
pip install pytest-gremlins

# Run mutation testing
pytest --gremlins

That's it. pytest-gremlins will instrument your code, release the gremlins, and report which ones your tests zapped (good!) and which survived (test gaps!).


Why pytest-gremlins?

Code coverage lies. It tells you what code your tests execute, but not whether your tests would catch bugs.

Mutation testing answers a harder question: If I introduce a bug, will my tests fail?

The Problem with Existing Tools

Tool Limitation
mutmut Unix/WSL only (requires fork()); not a pytest plugin
Cosmic Ray Complex setup; distributed mode requires Celery
MutPy Unmaintained (last update 2019), Python 3.4-3.7 only
mutatest Unmaintained (last update 2022)

See the full comparison guide for detailed, fair comparisons.

Our Solution: Speed Through Architecture

pytest-gremlins is fast because of how it works, not just parallelization:

  1. Mutation Switching - Instrument once, toggle mutations via environment variable
  2. Coverage Guidance - Only run tests that cover the mutated code
  3. Incremental Analysis - Skip unchanged code on repeat runs
  4. Parallel Execution - Safe parallelization with no shared state

Performance

Benchmarked against mutmut on a synthetic project:

Mode Time vs mutmut Speedup
--gremlins (sequential) 17.79s 14.90s 0.84x (see note)
--gremlins --gremlin-parallel 3.99s 14.90s 3.73x faster
--gremlins --gremlin-parallel --gremlin-cache 1.08s 14.90s 13.82x faster

Key findings:

  • Sequential mode is slower due to subprocess isolation overhead; detailed profiling shows 1.7x slower on small targets
  • Parallel mode delivers 3.73x speedup over mutmut
  • With caching, subsequent runs are 13.82x faster
  • pytest-gremlins found 117 mutations vs mutmut's 86, with 98% kill rate vs 86%

Example Output

================== pytest-gremlins mutation report ==================

Zapped: 142 gremlins (85%)
Survived: 18 gremlins (11%)
Timeout: 5 gremlins (3%)
Error: 2 gremlins (1%)

Top surviving gremlins:
  src/auth.py:42                   >= to >               (comparison)
  src/utils.py:17                  + to -                (arithmetic)
  src/api.py:88                    True to False         (boolean)

Run with --gremlin-report=html for detailed report.
=====================================================================

Timeout, Error, and Pardoned categories are only shown when their count is greater than zero.


Installation

# With pip
pip install pytest-gremlins

# With uv
uv add pytest-gremlins

# With poetry
poetry add pytest-gremlins

Requires Python 3.11+


Configuration

Zero configuration required for most projects. The plugin auto-discovers source paths from your pyproject.toml setuptools config (e.g., [tool.setuptools.packages.find]). If auto-discovery doesn't find your code, configure paths explicitly:

[tool.pytest-gremlins]
# Operators to use (default: all 5)
operators = ["comparison", "arithmetic", "boolean", "boundary", "return"]

# Paths to mutate (optional -- auto-discovered from setuptools metadata)
paths = ["src"]

# Patterns to exclude
exclude = ["**/migrations/*"]

# Report formats: "console", "html", "json" (default: console)
report = ["console", "html"]

# Enable incremental caching (default: false)
cache = true

# Fail if pardoned gremlins exceed 5% of total
max-pardons-pct = 5.0

The Gremlins Theme

We use Gremlins movie references as our domain language:

Traditional Term Gremlin Term Meaning
Original code Mogwai Your clean, untouched source code
Start mutation testing Feed after midnight Begin the mutation process
Mutant Gremlin A mutation injected into your code
Kill mutant Zap Your test caught the mutation
Surviving mutant Survivor Mutation your tests missed

Documentation

Full documentation: pytest-gremlins.readthedocs.io



Contributing

Contributions welcome! See our Contributing Guide.

This project uses strict TDD discipline with BDD/Gherkin scenarios. All contributions must include tests written before implementation.

Note on code coverage: We target 69% coverage due to inherent limitations in measuring pytest plugins (import timing, subprocess execution). See CONTRIBUTING.md for details.


License

MIT License. See LICENSE.


Changelog

See CHANGELOG.md for release history.

Metadata

Release files for pytest-gremlins 1.12.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-gremlins 1.12.1
File Size Uploaded Provenance Actions
pytest_gremlins-1.12.1.tar.gz 4.3 MB With provenance Details for pytest_gremlins-1.12.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-gremlins 1.12.1
File Interpreter ABI Platform Actions
pytest_gremlins-1.12.1-py3-none-any.whl Python 3 none any Details for pytest_gremlins-1.12.1-py3-none-any.whl

Total release size: 4.5 MB

Release files / pytest_gremlins-1.12.1.tar.gz

Download URL pytest_gremlins-1.12.1.tar.gz
Size 4.3 MB
Tags Source
SHA-256 checksum
How to use checksums
95c99ffe81b1ccc9311ae972f81c53245daab7350d4a18a52a6c0324f4fa8f8a
BLAKE2b-256 checksum
How to use checksums
28289be532ca6b6a75ea22aed5dafab4adc990ee449a856cb6af917da9c07b7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release files / pytest_gremlins-1.12.1-py3-none-any.whl

Download URL pytest_gremlins-1.12.1-py3-none-any.whl
Size 185.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b988a6519d62f4a0fb12cc5a44e01dd1cd238b9bc8e628b404d1c01b62d0b78
BLAKE2b-256 checksum
How to use checksums
2fa6b96d015b165464532b0bf6db9cb255e8d002a25e2ecc40686b87dc28e77c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Security for pytest-gremlins 1.12.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_gremlins-1.12.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.12.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page