Skip to main content

No project description provided

Project description

https://travis-ci.org/boxed/mutmut.svg?branch=master Documentation Status https://codecov.io/gh/boxed/mutmut/branch/master/graph/badge.svg

Mutmut is a mutation testing system for Python 2 and 3, with a strong focus on ease of use. If you don’t know what mutation testing is try starting with this article.

Some highlight features:

  • Found mutants can be applied on disk with a simple command making it very easy to work with the results

  • Supports all test runners (because mutmut only needs an exit code from the test command)

  • Extremely small and simple implementation (less than a thousand lines)

  • Battle tested on tri.struct, tri.declarative, tri.form and tri.table

  • Can use coverage data to only do mutation testing on covered lines

Install and run

You can get started with a simple:

> pip install mutmut
> mutmut run

This will by default run pytest on tests in the “tests” or “test” folder and it will try to figure out where the code to mutate lies. Run

mutmut --help

for the available flags, to use other runners, etc. The recommended way to use mutmut if the defaults aren’t working for you is to add a block in setup.cfg. Then when you come back to mutmut weeks later you don’t have to figure out the flags again, just run mutmut run and it works. Like this:

[mutmut]
paths_to_mutate=src/
backup=False
runner=python -m pytest
tests_dir=tests/
dict_synonyms=Struct, NamedStruct

You can stop the mutation run at any time and mutmut will restart where you left off. It’s also smart enough to retest only the surviving mutants when the test suite changes.

To print the results run mutmut results. It will give you output in the form of the commands to apply a mutation:

mutmut apply 3

You can just copy paste those lines and run and you’ll get the mutant on disk. You should REALLY have the file you mutate under source code control and committed before you mutate it!

Whitelisting

You can mark lines like this:

some_code_here()  # pragma: no mutate

to stop mutation on those lines. Some cases we’ve found where you need to whitelist lines are:

  • The version string on your library. You really shouldn’t have a test for this :P

  • Optimizing break instead of continue. The code runs fine when mutating break to continue, but it’s slower.

Example mutations

  • Integer literals are changed by adding 1. So 0 becomes 1, 5 becomes 6, etc.

  • < is changed to <=

  • break is changed to continue and vice versa

In general the idea is that the mutations should be as subtle as possible. See __init__.py for the full list.

Workflow

This section describes how to work with mutmut to enhance your test suite.

  1. Run mutmut with mutmut run. A full run is preferred but if you’re just getting started you can exit in the middle and start working with what you have found so far.

  2. Apply a surviving mutant to disk by copying and running the apply command from the output of mutmut results.

  3. Write a new test that fails

  4. Revert the mutant on disk

  5. Rerun the new test to see that it now passes

  6. Go back to point 2.

Mutmut keeps a result cache in .mutmut-cache so if you want to make sure you run a full mutmut run just delete this file.

You can also tell mutmut to just check a single mutant:

> mutmut run 3

JUnit XML support

In order to better integrate with CI/CD systems, mutmut supports the generation of a JUnit XML report (using https://pypi.org/project/junit-xml/). This option is available by calling mutmut junitxml. In order to define how to deal with suspicious and untested mutants, you can use mutmut junitxml –suspicious-policy=ignore –untested-policy=ignore. The possible values for these policies are:

  • ignore: Do not include the results on the report at all

  • skipped: Include the mutant on the report as “skipped”

  • error: Include the mutant on the report as “error”

  • failure: Include the mutant on the report as “failure”

If a failed mutant is included in the report, then the unified diff of the mutant will also be included for debugging purposes.

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

mutmut-1.2.0.tar.gz (20.6 kB view details)

Uploaded Source

File details

Details for the file mutmut-1.2.0.tar.gz.

File metadata

  • Download URL: mutmut-1.2.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/2.7.14

File hashes

Hashes for mutmut-1.2.0.tar.gz
Algorithm Hash digest
SHA256 c9f2ce4b2220e1f7c894c91e7d01bf7f53d7e5bd0a5dc9b1a9321c7279f34e58
MD5 2ed2aa5d9a2a094d560e647bb650e21b
BLAKE2b-256 9285f8f239d7c7ae7ec575c6c15bcf10d7c79792cbf0b722d3aa646e81018a15

See more details on using hashes here.

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