Zum Inhalt

Every pull request generates the mutants of the Python that it changes, with mutmut's own generator

  • Status: accepted, amends 0090
  • Date: 2026-11-28

Context

mutmut stops a run at the first file whose mutants aren't valid Python: create_mutants raises the first error of its pool, and no mutant runs. mutmut 3.8.1 writes such a file for a not whose wrapped condition a formatter puts in parentheses of its own, which it drops. The Mutation workflow ran only on its schedule, by hand and in a pull request that changes mutation.yml or the pin of mutmut (0090), so a pull request that changes only the Python never found out (#1167). In Dennis-Otto/issue-assistant#573, three pull requests changed issue_assistant/markup.py without a run, and the next update of the blueprint, which changes the pin, went red for a fault that it didn't bring.

mutmut has no command that only generates the mutants: mutmut run generates them and then always collects its stats, which need the tools of the tests and took 4 min 33 s in issue-assistant. Its generator, mutate_file_contents of mutmut.mutation.file_mutation, can be called on its own, with nothing but the pin of mutmut and its configuration.

Options

  1. Collect the stats in every pull request. That catches more, but costs minutes of every pull request and the tools of the tests.
  2. A step in check (python). That job would install mutmut as well, and its limit is measured against its own runs (1132).
  3. A job of its own in mutation.yml, without needs and without a path filter, that calls mutmut's generator for the changed files as mutmut run does and parses each result.

Decision

Option 3: the job mutation mutants.

  • What it reads: with the merge commit and main below it (fetch-depth: 2), blueprint.py mutation changes takes the changed files of the code in the source paths of mutmut, every file after a change of the pin, pyproject.toml, setup.cfg, .python-version, mutation.yml or the code of the check, and every file on a schedule and by hand. A pull request that changes none of them passes in seconds, as does a project without mutmut, such as a Nextcloud app, whose Infection counts a mutant with a syntax error as caught. A checkout without the commit below the merge fails the job rather than pass unchecked.
  • How it checks: blueprint.py mutation mutants takes the files that mutmut's own should_mutate() takes, calls the generator for each in one process per CPU, parses the result with ast as create_mutants_for_file does, skips a file that libcst can't read as mutmut does, and goes on after an invalid file, so that one run names every one: an annotation on the def of the function, with the module, the function, the mutant and the message of the parser, and the generated lines in the summary. It never imports mutmut.__main__, which mutmut 3.8 refuses to load on Windows.
  • A generator that changed fails with its own message: the generator isn't mutmut's public interface. Before any file, a probe generates the mutants of a function of two lines and makes sure that its first mutant is where line_span_by_function_name says; an import, a signature or a result that differs fails the check with a message that says that mutation mutants must follow the new version of mutmut, and never that the code is at fault. Since a change of the pin checks every file, an update of mutmut that changes it can't pass unnoticed.
  • The plan runs in every pull request: without the path filter, it finds out from the diff whether the pull request changes how the mutants run, and runs the stats and the sample only then, and when it can't tell.
  • Not required yet: the check reports in every pull request, but making it required, with the lists of the bots after the checks, is a decision of its own.

Consequences

  • A pull request that changes the Python of a project with mutmut takes one more job of about a minute, a large project such as the blueprint, with 52 files, about a minute and a half on four CPUs.
  • The first update of a repository to this release checks every file, so a repository whose code mutmut can't mutate gets a red check mutation mutants until the construct is written another way or a version of mutmut with the fix arrives.
  • An update of mutmut that changes its generator turns the check red until blueprint/mutation.py follows it.