How mutmut run works
mainThe mutmut run command operates in several distinct phases to ensure mutation testing is performed accurately and efficiently.
- Generating mutants: Creates a
./mutants/directory. It copies source files to this directory, applies mutations to.pyfiles, and copies additional required files (specified byalso_copy). - Collecting tests and stats: Identifies and executes tests to map which tests cover which mutants and tracks execution time for performance optimization. Results are stored in
./mutants/mutmut-stats.json. - Collecting mutation results: Loads existing results from
.metafiles located next to the mutated code (e.g.,mutants/foo/bar.py.meta). - Running clean tests: Runs the full test suite with all mutants disabled to verify the baseline test setup is functional.
- Running forced fail test: Verifies the mutation mechanism by forcing all mutants to raise an
Exception. This ensures the test suite actually detects changes in the code. - Running mutation testing: The core phase where each mutant is executed against the relevant subset of tests. If a test fails, the mutant is considered 'killed'. Results are persisted in
.metafiles.