Skip to content

Fix obsolete test names never being removed from the stats file - #569

Merged
nicklafleur merged 4 commits into
boxed:mainfrom
t-roi33:prune-obsolete-test-durations
Sep 12, 2026
Merged

nicklafleur merged 4 commits into
boxed:mainfrom
t-roi33:prune-obsolete-test-durations

Conversation

@t-roi33

@t-roi33 t-roi33 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #564. Replaces #568, whose commit is the first of the two here.

clear_out_obsolete_test_names is meant to drop the node IDs of deleted or
renamed tests from mutants/mutmut-stats.json. It never did, for two reasons:

  • count_before and count_after iterated the keys of
    tests_by_mangled_function_name, so they summed the lengths of the mangled
    names rather than the sizes of the test sets. The comprehension in between
    keeps every key, so the two sums were always equal, the "Removed N obsolete
    test names" message never printed and save_stats() never ran.
  • The filtering itself only covered tests_by_mangled_function_name. Obsolete
    node IDs in duration_by_test were never touched and stayed in the file for
    good.

Both come off one computation now: obsolete names are everything the stats file
knows minus what the collection run found. Both structures are pruned with that
set, and its size is what the message reports, which is what it says.

new_tests() is unaffected: it only looks at what is in the collection result
but not in the stats, and this removes nothing from the former.

The tests drive the real save_stats() into a tmp dir and check that both
structures reach the file pruned, plus the no-op case.

The before/after counters iterated the keys of
tests_by_mangled_function_name, so they measured the length of each
mangled function name instead of the size of its test set. The dict
comprehension between them keeps every key, so both sums were always
equal, the "Removed N obsolete test names" message never printed and
save_stats() never ran from here. Obsolete node IDs therefore stayed in
mutants/mutmut-stats.json indefinitely, even though the in-memory
filtering worked.

Count the test sets instead, and add a unit test that checks the
cleanup reaches the stats file.

Fixes #564
clear_out_obsolete_test_names only pruned tests_by_mangled_function_name,
so node IDs of deleted or moved tests stayed in duration_by_test in
mutants/mutmut-stats.json for good. Prune both structures from one set of
obsolete names, and report that set's size, which is what the message
"Removed N obsolete test names" says.
@t-roi33 t-roi33 changed the title Also drop obsolete test names from duration_by_test Drop obsolete test names from duration_by_test too Sep 8, 2026

@nicklafleur nicklafleur left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, I closed the other PR, we'll merge just this, in the future feel free to just combine the fixes for something like this.

Just rework the title and message a bit to reflect both fixes, thanks

Comment thread HISTORY.rst Outdated
@t-roi33 t-roi33 changed the title Drop obsolete test names from duration_by_test too Fix obsolete test names never being removed from the stats file Sep 9, 2026
@nicklafleur
nicklafleur merged commit 4ff5d9e into boxed:main Sep 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clear_out_obsolete_test_names never persists its cleanup: counters iterate keys instead of values

2 participants