Repository navigation
test: restore tilia.constants after re-importing it - #622
Merged
Merged
Conversation
test_tilia_metadata_not_found deletes tilia.constants from sys.modules and re-imports it with the package metadata mocked away, so APP_NAME is "". The other tests in the file re-import it too. None of them put the original module back, so the copy they built stays in sys.modules and on the tilia package for the rest of the process. Under pytest-xdist, whichever tests a worker runs next see that copy. test_lifecycle's file-association tests build the install path from APP_NAME and fail with "...\Local\current\.exe" instead of "...\Local\TiLiA\current\TiLiA.exe". Reruns don't help, since the copy is still loaded. Running the metadata test followed by tests/test_lifecycle.py reproduces it: 6 failures. An autouse fixture now restores both references after each test.
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.
tests/test_constants.pyre-importstilia.constantsto test how it handles missing package metadata, and never puts the original module back. The copy it leaves behind hasAPP_NAME == "", and every later test in the same process sees it.Under
pytest -n autothis depends on which tests share a worker, so it fails only sometimes. On #621 it hit the Windows / 3.10 job:--reruns=2can't recover, because the copy is still loaded when the test retries.An autouse fixture in
test_constants.pynow restores the module, both insys.modulesand as thetilia.constantsattribute, after each test. The tests themselves are unchanged.To reproduce:
pytest tests/test_constants.py::test_tilia_metadata_not_found tests/test_lifecycle.pyfails 6 tests ondevand passes with this change.