Skip to content

fix: diagnose silent test-to-mutant key mismatch in stats#516

Open
irajaryan wants to merge 1 commit intoboxed:mainfrom
irajaryan:fix/diagnose-test-mutant-key-mismatch
Open

fix: diagnose silent test-to-mutant key mismatch in stats#516
irajaryan wants to merge 1 commit intoboxed:mainfrom
irajaryan:fix/diagnose-test-mutant-key-mismatch

Conversation

@irajaryan
Copy link
Copy Markdown

This adds a sanity check after stats collection that detects when tests recorded trampoline hits but none match any mutant lookup key. Without it, the run silently completes with every mutant marked "No Tests" and 0.00 mutations/second.

The trampoline records orig.__module__ + '.' + orig.__name__ while per-mutant lookup uses the path-derived dotted name from get_mutant_name. They match in healthy projects (qualified package imports, source under ./, src/, or source/). They diverge when tests use top-level imports enabled by pytest's pythonpath config, conftest sys.path.insert, or non-conventional source dirs. The existing zero-check in run_stats_collection doesn't catch the divergence because hits are recorded, just under unmatchable keys.

The new _check_test_to_mutant_associations runs after collect_source_file_mutation_data and exits early with sample recorded vs expected keys, in the same style as the existing "Stopping early" diagnostic.

Same symptom appears in #341, #351, #416, #419, all closed after users fixed their project setup. This change surfaces the cause earlier.

Fixes #515

When tests import source under a different module path than mutmut
derives from the file path (e.g. via pythonpath in pytest config or
conftest sys.path injection), every mutant is silently marked "No
Tests" because trampoline hits are recorded under __module__-based
keys that the path-derived mutant lookup can never match.

Add a check after collect_source_file_mutation_data that detects this
disjoint-keys case and exits early with sample recorded vs expected
keys, mirroring the existing "Stopping early" diagnostic in
run_stats_collection.

Fixes boxed#515
@irajaryan irajaryan force-pushed the fix/diagnose-test-mutant-key-mismatch branch from e5e5bf6 to 50425d5 Compare May 8, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All mutants reported as "No Tests" when test imports differ from the file-path module name

1 participant