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
+5 -5
View File
@@ -1,7 +1,7 @@
"""Files whose tests import them by file name, which mutmut names right only from the file's own folder.
"""Files that tests import by their file name, which mutmut finds only when it runs in the file's own folder.
A test in docker/scripts/ that runs `import run_harness` gets it because pytest, or unittest's discover, puts that folder on sys.path. mutmut run from the
checkout's top names the same file docker.scripts.run_harness, and finds none of the tests' calls to it."""
checkout's top names the same file docker.scripts.run_harness, so it finds none of the tests' calls to it."""
import ast
import os
import pathlib
@@ -11,9 +11,9 @@ from mutate_changes.changed_lines import is_test
def imported_by_file_name(top: str, grouped: dict[str, dict[str, frozenset[int]]], configs: tuple[str, ...]) -> dict[str, dict[str, frozenset[int]]]:
"""grouped, with each file of the checkout's top group that a test beside it imports by its file name moved to its own folder.
"""grouped, with each file in its "." group moved to its own folder where a test beside it imports it by its file name and the folder has no __init__.py.
A file in a folder that holds one of configs stays: the settings there decide how its tests import it. So do all files where the top holds one."""
A file in a folder that holds one of configs stays, as does every file where the top holds one: the settings there decide how its tests import it."""
if "." not in grouped or any(os.path.isfile(os.path.join(top, name)) for name in configs):
return grouped
regrouped: dict[str, dict[str, frozenset[int]]] = {name: files for name, files in grouped.items() if name != "."}
@@ -25,7 +25,7 @@ def imported_by_file_name(top: str, grouped: dict[str, dict[str, frozenset[int]]
def top_level_imports(folder: str) -> set[str]:
"""The modules the test files in folder import by their first name. A test file that doesn't parse names none."""
"""The top-level module names that the test files in folder import, as `a` for `import a.b`. A test file that can't be read or parsed adds none."""
names: set[str] = set()
for test in sorted(pathlib.Path(folder).glob("*.py")):
if not is_test(test.name):