Repository navigation
test: keep the render-body snapshot tests independent of Django's settings - #409
Merged
Merged
Conversation
…tings `test_render_body_snapshots.py` counts paused slot fallbacks by walking `gc.get_objects()` with `isinstance(value, types.GeneratorType)`. `isinstance` reads an object's `__class__`, and on a Django lazy object such as `staticfiles_storage` that builds the object, which raises `ImproperlyConfigured` when Django's settings leave `STATIC_URL` unset. So the 14 snapshot tests failed whenever they shared a process with `test_contrib_request.py` or `test_events_host_parity.py`, as they do under xdist, and passed alone. The check now compares the exact type. A generator type cannot be subclassed, so it finds the same objects and runs no other code. Run after each of those two files in one process, the snapshot file now passes (166 and 131 tests); before, 14 tests failed in each run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
|
From the duplicate #418: I swept the repo for the same pattern. The only other |
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.
test_render_body_snapshots.pyfailed with 14 tests whenever it shared a pytest process with a test that leaves Django configured withoutSTATIC_URL, such astest_contrib_request.pyortest_events_host_parity.py. Under xdist this happened depending on how tests were spread across workers. Alone, the file passed.Why
The tests count paused slot fallbacks by walking
gc.get_objects()withisinstance(value, types.GeneratorType).isinstancereads an object's__class__. On a Django lazy object such asstaticfiles_storage, that builds the object, which raisesImproperlyConfiguredwhenSTATIC_URLis not set.The change
The check compares the exact type:
type(value) is types.GeneratorType. A generator type cannot be subclassed, so it finds the same objects and runs no other code. A comment says why. No othergc.get_objects()loop in the tests usesisinstance.Checks
test_contrib_request.py, then the snapshot filetest_events_host_parity.py, then the snapshot file🤖 Generated with Claude Code