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
+9 -7
View File
@@ -3,8 +3,8 @@
mutmut names a mutant `<module>.<key>__mutmut_<number>`. The key is x_<function> for a function at a module's top, and xǁ<class>ǁ<method> for a method of a class there; mutmut mutates no other code. Its mutants/ copy of a file holds the original of each function mutmut mutates, as `<key>__mutmut_orig`, and each mutant as a changed copy of that original."""
import ast
import functools
import re
from typing import NamedTuple
import re
from collections.abc import Sequence
@@ -42,17 +42,19 @@ def named(name: str, paths: list[str]) -> tuple[str, str, int] | None:
TRACEBACK = "Traceback (most recent call last):"
FRAME = re.compile(r'^\s*File ".*?[/\\](mutmut[/\\].*?|[^/\\]*?)", line (\d+)', re.MULTILINE)
FRAME = re.compile(r'^\s*File "(.*?)", line (\d+)', re.MULTILINE)
MUTMUT_FILE = re.compile(r"[/\\]site-packages[/\\](mutmut[/\\].*)")
def crash_in_mutmut(output: str) -> str | None:
"""The error and place of the last traceback in output, where it ends in a frame inside mutmut's own code, else None."""
"""The error and place of the last traceback in output, where its last frame is in the mutmut package, else None."""
block = output.rpartition(TRACEBACK)[2] if TRACEBACK in output else ""
frames = FRAME.findall(block)
lines = block.strip().splitlines()
if not frames or not lines or not frames[-1][0].startswith("mutmut"):
frames = list(FRAME.finditer(block))
if not frames:
return None
return f"{lines[-1]}, in {frames[-1][0].replace(chr(92), '/')} line {frames[-1][1]}"
installed = MUTMUT_FILE.search(frames[-1][1])
error = next((line for line in block[frames[-1].end():].splitlines()[1:] if line and not line[0].isspace()), "")
return f"{error}, in {installed[1].replace(chr(92), '/')} line {frames[-1][2]}" if installed and error else None
def statuses(results: str) -> dict[str, str]: