Have mutmut copy each entry of the folder rather than '.', which copied mutants/ into itself and collected the tests twice

This commit is contained in:
2026-11-11 19:14:49 +01:00
parent e99eef43b9
commit 79e8ce1368
3 changed files with 42 additions and 46 deletions
+9 -15
View File
@@ -1,7 +1,6 @@
"""The setup.cfg that has mutmut mutate a branch's changed files, and the tests left out because they fail before any mutant."""
import configparser
import io
import os
import re
from failure import Failure
@@ -18,10 +17,11 @@ class CaseKept(configparser.ConfigParser):
return optionstr
def mutmut_config(existing: str, sources: list[str], left: list[str]) -> str | Failure:
"""The setup.cfg that has mutmut mutate the sources, copy the rest of the folder, which their tests import, and pass pytest the options that leave tests out.
def mutmut_config(existing: str, sources: list[str], copied: list[str], left: list[str]) -> str | Failure:
"""The setup.cfg that has mutmut mutate the sources, copy the folder's other entries, which their tests import, and pass pytest the options that leave tests out.
existing is the project's own setup.cfg, empty where it has none. Its settings stay, though its comments go, and its [mutmut] pytest_add_cli_args come before the options that leave tests out."""
copied names each file and folder at the folder's top. Not ".": mutmut makes mutants/ before it copies, so "." would copy mutants/ into itself and
pytest would collect the tests twice. existing is the project's own setup.cfg, empty where it has none. Its settings stay, though its comments go, and its [mutmut] pytest_add_cli_args come before the options that leave tests out."""
config = CaseKept(interpolation=None)
try:
config.read_string(existing)
@@ -31,7 +31,7 @@ def mutmut_config(existing: str, sources: list[str], left: list[str]) -> str | F
config.add_section("mutmut")
section = config["mutmut"]
section["source_paths"] = listed(sources)
section["also_copy"] = "."
section["also_copy"] = listed(copied)
if left:
section["pytest_add_cli_args"] = "\n".join(filter(None, [section.get("pytest_add_cli_args", ""), listed(left)]))
written = io.StringIO()
@@ -45,14 +45,8 @@ def listed(items: list[str]) -> str:
def left_out(output: str) -> list[str]:
"""The nodeid of each test, or test file that failed to collect, that a failed run's short summary reports."""
"""The pytest options that leave out each test a failed run's short summary reports: --deselect for a test, --ignore for a file that failed to collect."""
summary = SUMMARY.split(output)
return REPORTED.findall(summary[-1]) if len(summary) > 1 else []
def leaving_out(nodeids: list[str], copy: str) -> list[str]:
"""The pytest options that leave out each nodeid: --deselect for a test, --ignore for a file.
mutmut 3.8.1 runs pytest in copy's mutants/ folder, yet pytest 9.2 reports each nodeid from copy, as mutants/<path>. --deselect takes the
nodeid as reported, and --ignore an absolute path, built the same way whether or not the nodeid starts with mutants/."""
return [f"--deselect={nodeid}" if "::" in nodeid else f"--ignore={os.path.join(copy, 'mutants', nodeid.removeprefix('mutants/'))}" for nodeid in nodeids]
if len(summary) < 2:
return []
return [f"--deselect={nodeid}" if "::" in nodeid else f"--ignore={nodeid}" for nodeid in REPORTED.findall(summary[-1])]