✅ Fix order-dependent tests in test_dependency_contextmanager.py - #16368
Open
meagoodboy wants to merge 1 commit into
Open
meagoodboy wants to merge 1 commit into
meagoodboy wants to merge 1 commit into
Conversation
meagoodboy
marked this pull request as ready for review
September 16, 2026 11:47
This branch has not been deployed
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_dependency_contextmanager.pykeeps a module-levelstatedict (and anerrorslist) that the app's yield dependencies mutate in place. Four tests open by asserting the pristine value, so they only pass if nothing else in the file ran first. The file passes in definition order but any other order breaks it:$ pytest tests/test_dependency_contextmanager.py::test_sync_async_state tests/test_dependency_contextmanager.py::test_async_statepytest honors CLI order, so naming the two tests in reversed order is enough to trigger it. Running the whole file in reverse definition order fails 4 of 22 tests (
test_async_state,test_sync_state,test_async_raise_other,test_sync_raise_other), and random shuffles (for example under pytest-randomly) fail 2 to 4 tests depending on the seed.This PR resets the shared state between tests with an autouse fixture, the same pattern
tests/test_dependency_yield_except_httpexception.pyalready uses for the same reason. The file now passes in definition order, reversed, and shuffled. The reset cannot change what the existing tests check: everyerrorsassertion is a membership check after the test's own request, and everystateassertion reads keys the test itself transitions.Tests only, no library changes.