python
runtime_error
ai_generated
true
AssertionError: assert datetime.date(2025, 1, 1) == datetime.date(2024, 12, 31) # only fails in CI in UTC
ID: python/pytest-freezegun-timezone
80%Fix Rate
82%Confidence
0Evidence
2025-09-19First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.5 | active | — | — | — |
Root Cause
freezegun freezes UTC time by default; tests that assert on local time or use timezone-aware code fail when developer machine TZ differs from CI TZ.
generic中文
freezegun 默认冻结 UTC 时间;断言本地时间或使用时区感知代码的测试在开发者机器 TZ 与 CI TZ 不同时失败。
Workarounds
-
90% success
from freezegun import freeze_time @freeze_time('2025-01-01 00:00:00', tz_offset=0) def test_x(): ... # or use tz-aware datetimes in assertions -
88% success
from datetime import datetime, timezone now = datetime.now(timezone.utc) # assert against UTC-aware values in tests
Dead Ends
Common approaches that don't work:
-
85% fail
Makes CI match freezegun but local runs diverge; the underlying timezone-aware bug remains.
-
90% fail
freezegun interprets the string as UTC; local-time assertions still fail.
-
80% fail
Tests become flaky around midnight and month boundaries; loses determinism.