Answer stability round 1: 0 🔴, 2 🟡 (0 misread); tell mutmut's own frames by their site-packages path, take the error from after the last frame, and fix the module docstring and help

This commit is contained in:
Lilleman
2026-11-20 21:26:22 +01:00
parent 8d896d772d
commit ce0344f703
6 changed files with 55 additions and 43 deletions
+12 -12
View File
@@ -1,8 +1,8 @@
"""Mutate the changed lines of a branch's Python files with mutmut 3, in a scratch copy of the folder each file's tests run from.
mutmut reads its settings from the folder it runs in, writes beside them, and names each module by its path from there. So each file is
mutated from the nearest folder above it, up to the checkout's top, that holds a setup.cfg or a pyproject.toml: the folder its tests
import it from."""
mutated from the folder its tests import it from: the nearest folder above it, up to the checkout's top, that holds a setup.cfg or a
pyproject.toml, or the file's own folder where a test beside it imports it by its file name (bare_imports.py)."""
import dataclasses
import os
import pathlib
@@ -10,12 +10,12 @@ import posixpath
import shutil
import tomllib
from mutate_changes.bare_imports import imported_by_file_name
from mutate_changes.changed_lines import by_folder, label
from mutate_changes.mutmut_mutants import crash_in_mutmut, function_keys, mutant_globs, mutated_line, named, statuses
from mutate_changes.tool_process import failed, Ran, remove, Run, scratch_folder
from failure import Failure
from mutate_changes.mutmut_mutants import crash_in_mutmut, function_keys, mutant_globs, mutated_line, named, statuses
from git_cli.git_repo import Git
from mutate_changes.bare_imports import imported_by_file_name
from mutate_changes.mutmut_setup import left_out, mutmut_config
CAUGHT = frozenset({"caught by type check", "killed"})
@@ -127,7 +127,10 @@ def mutate_copy(copy: str, copied: list[str], folder: Folder, argv: list[str], r
ran = run_until_stats_pass(copy, copied, folder, argv, run)
if isinstance(ran, Failure):
return ran
output, left = ran
(output, code), left = ran
crash = crash_in_mutmut(output)
if code and crash:
return [f"mutmut in {folder.label} crashed with {crash}: mutate its changed lines by hand."]
if not os.path.isdir(os.path.join(copy, "mutants")):
return Failure(f"mutmut in {folder.label} wrote no mutants/ in {copy}; --prefix must run it in $PWD")
if NO_MUTANT in output:
@@ -142,8 +145,8 @@ def mutate_copy(copy: str, copied: list[str], folder: Folder, argv: list[str], r
return [f"mutmut in {folder.label}: {counted} mutants on changed lines, {len(shown)} not killed.{unreached}{left_note}", *shown]
def run_until_stats_pass(copy: str, copied: list[str], folder: Folder, argv: list[str], run: Run) -> tuple[str, list[str]] | Failure:
"""mutmut's output, and the options that left out each test that fails before any mutant: mutmut runs no mutant while one fails."""
def run_until_stats_pass(copy: str, copied: list[str], folder: Folder, argv: list[str], run: Run) -> tuple[tuple[str, int], list[str]] | Failure:
"""mutmut's output and exit code, and the options that left out each test that fails before any mutant: mutmut runs no mutant while one fails."""
ran = configured_run(copy, copied, folder, [], argv, run)
left: list[str] = []
if isinstance(ran, Ran) and STATS_FAILED in ran.output:
@@ -152,12 +155,9 @@ def run_until_stats_pass(copy: str, copied: list[str], folder: Folder, argv: lis
ran = configured_run(copy, copied, folder, left, argv, run)
if isinstance(ran, Failure):
return ran
if ran.code and NO_MUTANT not in ran.output and NO_TEST not in ran.output:
crash = crash_in_mutmut(ran.output)
if crash:
return Failure(f"mutmut crashed in {folder.label} with {crash}: mutate the changed lines of {folder.label} by hand.")
if ran.code and NO_MUTANT not in ran.output and NO_TEST not in ran.output and not crash_in_mutmut(ran.output):
return failed(f"mutmut run in {folder.label}", ran)
return ran.output, left
return (ran.output, ran.code), left
def configured_run(copy: str, copied: list[str], folder: Folder, options: list[str], argv: list[str], run: Run) -> Ran | Failure: