Repository navigation
Conversation
Trampolined functions called while pytest imports test and source modules were left in state()._stats and credited to whichever test ran first. A function only called at import time therefore looked covered, so its mutants were reported as survived instead of no tests. Clear the buffer in pytest_collection_finish, which runs after collection and before the first test.
Author
|
Ran the repro from the report in this environment, on unmodified
The false survivors are gone and the stats file no longer credits |
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.
state()._statsis only cleared inpytest_runtest_teardown, so the calls made while pytest imports the test and source modules survive until the first test finishes and get credited to it. In the repro from #641 that credits_tabletotest_double, and_table's mutants are then reported assurvivedeven thoughtest_lookupwould kill them.This adds
pytest_collection_finishtoStatsCollectorand clears the buffer there, so only calls made while a test runs are attributed to it.Scope. This is the first part the issue asks for. A function that only runs at import now has no tests, so its mutants show as
no testsinstead of a falsesurvived. Making them killable requires importing the module withMUTANT_UNDER_TESTalready set, which is a separate change and is not attempted here.Test. The new test drives the collector directly rather than running a nested pytest session: it records a hit, fires
pytest_collection_finish, then asserts the first test only picks up the hit recorded during its own run. It fails onmainwithAttributeError: 'StatsCollector' object has no attribute 'pytest_collection_finish'.Notes:
HammettRunner.run_statshas the same shape inpost_test_callback, but hammett exposes no collection hook, so that path is unchanged.tests/e2e/test_e2e_my_lib.py::test_my_lib_result_snapshotfails in my environment on unmodifiedmaintoo; everything else passes (470 passed, 3 skipped,--ignore=tests/e2e).Refs #641.