Repository navigation
Re-run mutants when tests are edited or added - #635
Open
nafiurahman00 wants to merge 1 commit into
Open
nafiurahman00 wants to merge 1 commit into
nafiurahman00 wants to merge 1 commit into
Conversation
Cached results were only invalidated when the source changed, so removing an assertion from a test left its mutants as "killed", and a new test that kills a survivor didn't change anything until mutants/ was deleted. Store a hash of each test file (and the conftest.py files above it). When a test file changes, its tests are collected again and the mutants of the functions they covered are re-run. Functions covered by new tests get their survived/no tests results reset. conftest.py changes go through on_dependency_change since they can affect every test. Fixes boxed#626
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #626
Cached results were only reset when the source code changed. Test files don't have function hashes and
git_changed_non_py_files()skips all.pyfiles, so after removing an assertion from a test,mutmut runkept reporting the mutants it used to kill as killed. The other direction was broken too: adding a test that kills a survivor didn't re-run it (the case @snapshotpl mentioned).I went with the targeted approach suggested in the thread rather than rerunning everything on any test change:
conftest.pyfiles above them (test_file_hashesinmutmut-stats.json)survived/no testsresults reset. Killed ones are kept, since more coverage can't un-kill a mutantconftest.pycan affect every test, so a change there goes throughon_dependency_changelike the other watched files (warns by default, until the next full run)Old stats files without
test_file_hashesstill load, and the hashes are recorded on the next run.I also changed the "non-Python file(s) changed" message to "dependency file(s) changed" since conftest.py can show up there now, and updated the README section that said Python changes are already tracked per function.
Tested with the script from the issue, with a second test file that gets a stronger assertion:
I also checked a run with no changes (nothing re-run), editing only one test file (only its functions re-run), and adding a conftest.py with both
warnandrerun. Added unit tests intests/mutation/test_mutation.py.uv run pytestpasses (488 passed, 4 skipped) and so doespre-commit run --all-files.One thing I noticed while testing: deleting a test file doesn't remove its copy from
mutants/, so the deleted test still runs. That's a separate bug on main, fixed in #636.