Skip to content

test: keep the render-body snapshot tests independent of Django's settings - #409

Merged
JuroOravec merged 1 commit into
mainfrom
fix/snapshot-test-isolation
Oct 25, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/snapshot-test-isolation

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

test_render_body_snapshots.py failed with 14 tests whenever it shared a pytest process with a test that leaves Django configured without STATIC_URL, such as test_contrib_request.py or test_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() with isinstance(value, types.GeneratorType). isinstance reads an object's __class__. On a Django lazy object such as staticfiles_storage, that builds the object, which raises ImproperlyConfigured when STATIC_URL is 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 other gc.get_objects() loop in the tests uses isinstance.

Checks

Run in one process Before After
test_contrib_request.py, then the snapshot file 14 failed 166 passed
test_events_host_parity.py, then the snapshot file 14 failed 131 passed

🤖 Generated with Claude Code

…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]>
@JuroOravec
JuroOravec merged commit de5f364 into main Oct 25, 2026
14 of 26 checks passed
@JuroOravec
JuroOravec deleted the fix/snapshot-test-isolation branch October 25, 2026 15:57
@JuroOravec

Copy link
Copy Markdown
Member Author

From the duplicate #418: I swept the repo for the same pattern. The only other gc.get_objects() scan is in packages/py/citry/tests/test_native_render_rows.py, and it already compares type(item) is native._RowPlan. No library or docs code walks gc objects, and I found no other isinstance call over arbitrary live objects that could wake a lazy Django proxy.

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