Skip to content

test: restore tilia.constants after re-importing it - #622

Merged
azfoo merged 1 commit into
devfrom
fix/test-constants-leak
Oct 2, 2026
Merged

azfoo merged 1 commit into
devfrom
fix/test-constants-leak

Conversation

@azfoo

@azfoo azfoo commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

tests/test_constants.py re-imports tilia.constants to test how it handles missing package metadata, and never puts the original module back. The copy it leaves behind has APP_NAME == "", and every later test in the same process sees it.

Under pytest -n auto this depends on which tests share a worker, so it fails only sometimes. On #621 it hit the Windows / 3.10 job:

FAILED tests/test_lifecycle.py::TestWindowsFileAssociation::test_register_points_commands_at_the_velopack_current_path
- "C:\Users\test\AppData\Local\TiLiA\current\TiLiA.exe" "%1"
+ "C:\Users\test\AppData\Local\current\.exe" "%1"

--reruns=2 can't recover, because the copy is still loaded when the test retries.

An autouse fixture in test_constants.py now restores the module, both in sys.modules and as the tilia.constants attribute, after each test. The tests themselves are unchanged.

To reproduce: pytest tests/test_constants.py::test_tilia_metadata_not_found tests/test_lifecycle.py fails 6 tests on dev and passes with this change.

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.
@azfoo
azfoo merged commit 1f4e0d5 into dev Oct 2, 2026
11 checks passed
@azfoo
azfoo deleted the fix/test-constants-leak branch October 2, 2026 16:40
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.

1 participant