Skip to content

Stop one beat-import test reading the installed tzdata - #158

Merged
PhiLily merged 1 commit into
mainfrom
fix/beat-zone-equivalence-test-by-construction
Oct 28, 2026
Merged

PhiLily merged 1 commit into
mainfrom
fix/beat-zone-equivalence-test-by-construction

Conversation

@PhiLily

@PhiLily PhiLily commented Oct 27, 2026

Copy link
Copy Markdown
Member

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.

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
PhiLily force-pushed the fix/beat-zone-equivalence-test-by-construction branch from 3eb0c3e to 2d0cb57 Compare October 28, 2026 06:42
@PhiLily
PhiLily merged commit da4b371 into main Oct 28, 2026
57 of 58 checks passed
@PhiLily
PhiLily deleted the fix/beat-zone-equivalence-test-by-construction branch October 28, 2026 07:44
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