Repository navigation
Stop one beat-import test reading the installed tzdata - #158
Merged
Merged
Conversation
One test in tests/test_import_beat.py asserted that ox_import_beat_schedules treats US/Eastern and America/New_York as one zone by reading both from the installed tz database and comparing their bytes. The command counts two keys as one zone only when their data files are identical, since equal offsets today say nothing about either zone's future rules, so the test passed or failed with the installed tzdata rather than with the code. The test now writes the same synthetic TZif data under both keys through the zone_files fixture, the way test_two_names_for_the_same_zone_data_are_one_zone in the same file already does, so the bytes it compares are the test's own. The real zone names stay, since the point is that this legacy-name pair is translated as one zone. The dev dependency group now requires pytest>=8.0,<9.2. pytest 9.2.0 changed how monkeypatch.setattr records the value it will restore: it reads that value from the target's own __dict__ rather than through getattr, so that patching an attribute an instance inherits from its class no longer leaves a shadowing entry on the instance at teardown. Django's proxies, django.contrib.admin.sites.site and django.db.connection among them, delegate every attribute to a wrapped object and hold none of those attributes in their own __dict__, so for them that lookup finds nothing every time, and teardown deletes the attribute from the wrapped object instead of restoring it. Where the wrapped class defines the attribute, as DatabaseWrapper defines _commit, the deletion uncovers the class's own and nothing is lost. Where only the wrapped instance has it, as AdminSite has _actions, the deletion is permanent, and every later test in the process that reads it fails. tests/test_schedule_admin_unreadable_actions.py patches site._actions. The pin excludes the whole 9.2 line rather than 9.2.0 alone, so a later 9.2 release with the same behaviour cannot reach the suite. It stands until a release restores attributes patched through a proxy. The comment beside the pin in pyproject.toml records this. Two tests in tests/test_dispatch_errors.py, test_a_commit_that_fails_is_not_a_callback_failure and test_a_commit_that_loses_the_connection_ends_the_pass, replaced django.db.connection._commit through monkeypatch.setattr, and the replacement itself called monkeypatch.setattr on the same attribute to put the original back. That puts two undo entries for one attribute on monkeypatch's stack, and nothing about its teardown promises to unwind them into the state either test wants: with the bookkeeping above, both entries record the attribute as absent, teardown deletes it twice, and the second deletion raises AttributeError. Each test now patches _commit once, and the replacement calls the captured original directly: the first raises on its first call and commits on every later one, the second ends the session before calling the original. No application code changes.
PhiLily
force-pushed
the
fix/beat-zone-equivalence-test-by-construction
branch
from
October 28, 2026 06:42
3eb0c3e to
2d0cb57
Compare
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.
One test in tests/test_import_beat.py asserted that
ox_import_beat_schedules treats US/Eastern and America/New_York as one
zone by reading both from the installed tz database and comparing
their bytes. The command counts two keys as one zone only when their
data files are identical, since equal offsets today say nothing about
either zone's future rules, so the test passed or failed with the
installed tzdata rather than with the code.
The test now writes the same synthetic TZif data under both keys
through the zone_files fixture, the way
test_two_names_for_the_same_zone_data_are_one_zone in the same file
already does, so the bytes it compares are the test's own. The real
zone names stay, since the point is that this legacy-name pair is
translated as one zone. No application code changes.