Python mutation testing: test your tests! Safely run mutation trials without source code modifications and see what will get past your test suite.

EvanKepner, updated 🕥 2023-02-17 12:23:43

mutatest: Python mutation testing

| |py-versions| |license| |ci-azure| |docs| |coverage| |black| | |pypi-version| |pypi-status| |pypi-format| |pypi-downloads| | |conda-version| |conda-recipe| |conda-platform| |conda-downloads|

Are you confident in your tests? Try out mutatest and see if your tests will detect small modifications (mutations) in the code. Surviving mutations represent subtle changes that are undetectable by your tests. These mutants are potential modifications in source code that continuous integration checks would miss.


- Simple command line tool with `multiple configuration options <>`_.
- Built on Python's Abstract Syntax Tree (AST) grammar to ensure `mutants are valid <>`_.
- `No source code modification <>`_,
  only the ``__pycache__`` is changed.
- Uses ``coverage`` to create `only meaningful mutants <>`_.
- Built for efficiency with `multiple running modes <>`_
  and `random sampling of mutation targets <>`_.
- Capable of running `parallel mutation trials <>`_
  with multiprocessing on Python 3.8.
- Flexible enough to run on a `whole package <>`_
  or a `single file <>`_.
- Includes an `API for custom mutation controls <>`_.
- Tested on Linux, Windows, and MacOS with `Azure pipelines <>`_.
- Full strict static type annotations throughout the source code and the API.


Install from PyPI <>_:

.. code-block:: bash

$ pip install mutatest

Install from conda-forge <>_:

.. code-block:: bash

$ conda install -c conda-forge mutatest

Example Output

This is an output example running mutation trials against the API Tutorial example folder <>_ example folder.

.. code-block:: bash

$ mutatest -s example/ -t "pytest" -r 314

Running clean trial
2 mutation targets found in example/ AST.
1 mutation targets found in example/ AST.
Setting random.seed to: 314
Total sample space size: 2
10 exceeds sample space, using full sample: 2.

Starting individual mutation trials!
Current target location:, LocIndex(ast_class='BinOp', lineno=6, col_offset=11, op_type=<class '_ast.Add'>)
Detected mutation at example/ (6, 11)
Detected mutation at example/ (6, 11)
Surviving mutation at example/ (6, 11)
Break on survival: stopping further mutations at location.

Current target location:, LocIndex(ast_class='CompareIs', lineno=6, col_offset=11, op_type=<class '_ast.Is'>)
Detected mutation at example/ (6, 11)
Running clean trial

Mutatest diagnostic summary
 - Source location: /home/user/Github/mutatest/docs/api_tutorial/example
 - Test commands: ['pytest']
 - Mode: s
 - Excluded files: []
 - N locations input: 10
 - Random seed: 314

Random sample details
 - Total locations mutated: 2
 - Total locations identified: 2
 - Location sample coverage: 100.00 %

Running time details
 - Clean trial 1 run time: 0:00:00.348999
 - Clean trial 2 run time: 0:00:00.350213
 - Mutation trials total run time: 0:00:01.389095

Trial Summary Report:

Overall mutation trial summary
 - RUN DATETIME: 2019-10-17 16:57:08.645355

Detected mutations:

 - example/ (l: 6, c: 11) - mutation from <class '_ast.Add'> to <class '_ast.Sub'>
 - example/ (l: 6, c: 11) - mutation from <class '_ast.Add'> to <class '_ast.Mod'>
 - example/ (l: 6, c: 11) - mutation from <class '_ast.Is'> to <class '_ast.IsNot'>

Surviving mutations:

 - example/ (l: 6, c: 11) - mutation from <class '_ast.Add'> to <class '_ast.Mult'>


For full documentation, including installation, CLI references, API references, and tutorials, please see The project is hosted on PyPI at


Please use the GitHub issue tracker <> to submit bugs or request features. See the Contributing Guidelines <> if you are interested in submitting code in the form of pull requests.


Consult the Changelog <>_ page for fixes and enhancements of each version.


Copyright Evan Kepner 2018-2020.

Distributed under the terms of the MIT <>_ license, mutatest is free and open source software.

.. |py-versions| image:: :target: :alt: Python versions .. |license| image:: :target: :alt: License .. |pypi-version| image:: :target: :alt: PyPI version .. |pypi-status| image:: :target: :alt: PyPI status .. |pypi-format| image:: :target: :alt: PyPI Format .. |pypi-downloads| image:: :target: :alt: PyPI Downloads .. |ci-travis| image:: :target: :alt: TravisCI .. |ci-azure| image:: :target: :alt: Azure Pipelines .. |docs| image:: :target: :alt: RTD status .. |coverage| image:: :target: :alt: CodeCov .. |black| image:: :target: :alt: Black .. |conda-recipe| image:: :target: :alt: Conda recipe .. |conda-version| image:: :target: :alt: Conda version .. |conda-platform| image:: :target: :alt: Conda platforms .. |conda-azure| image:: :target: :alt: Conda azure status .. |conda-downloads| image:: :target: :alt: Conda downloads


known issue: type hints are not ignored as mutation targets

opened on 2019-04-08 20:11:45 by EvanKepner

specifically in the name-constant category for None or boolean


Maintenance patches 2022-02-20 19:25:39


Maintenance: argument parsing logical changes 2020-05-16 14:15:07

Bug fix: KeyError with bit-shift mutations 2020-03-11 12:27:32

Parallel cache and bug fixes 2020-01-20 20:36:39

This is the stable release: -

Support for setup.cfg config 2020-01-17 02:28:40

  • Support for using setup.cfg for config entries like mutatest.ini as an alternate source file.

Maintenance: Windows filepath test failure fix 2020-01-08 00:03:21

  • Discovered the mock coverage files were UNIX-specific paths, updated testing structure for filters specifically to use os-agnostic mocks and to allow optional relative vs. full resolution of the file passed in the coverage filter.

mutation-testing python3 unit-test mutation python37 python38