Skip to content

Commit d48cb22

Browse files
springfall2008CIclaude
authored
fix(tests): anchor the energydataservice fixture to Predbat's day, not the host's (#5013)
test_energydataservice built its rate fixture from datetime.now() - the machine's clock - while reading the timezone offset two lines later from my_predbat.midnight_utc, which is local midnight in Predbat's configured timezone. Between 23:00 and 00:00 UTC under BST those land on different dates, so the published rates are a day out from the day the code is modelling and rates[1440] does not exist: KeyError: 1440. This is not intermittent. The nightly journal flush runs at local midnight, which during BST is 23:0x UTC, so it lands in the failing hour every night - PR #5011 is a docs-only change that failed CI for exactly this reason, at 23:12 UTC. Same trap and same fix as PR #4998 for the multi-car IOG tests, and the trap already has a bullet in the debug journal ("Build test dates from Predbat's clock, not the machine's"). Verified by running the suite with TZ=Pacific/Pitcairn, which puts the host a calendar day behind Europe/London: energydataservice reproduces the KeyError before the change and passes after, as does the full quick suite (82.98s, 4 slow tests skipped). It also still passes on an unshifted clock. The suite aborts on the first uncaught exception, so this was masking anything later in the run; with it fixed, nothing else in the quick suite fails in that window. Nineteen other test files call datetime.now(), none of them currently affected, but the pattern is latent - a scheduled CI run in a shifted timezone would catch the next one before a maintainer does. Co-authored-by: CI <ci@example.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent eb9e1e1 commit d48cb22

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎apps/predbat/tests/test_energydataservice.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ def test_energydataservice(my_predbat):
1919
failed = 0
2020

2121
print("Test energy data service")
22-
today = datetime.now().strftime("%Y-%m-%d")
23-
tomorrow = (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d")
22+
# Anchor the fixture to Predbat's own day, not the host's. midnight_utc is local midnight
23+
# in the configured timezone (Europe/London in the harness); datetime.now() is the machine's
24+
# clock. Between 23:00 and 00:00 UTC under BST those land on different dates, the published
25+
# rates are then a day out from the day the code is modelling, and rates[1440] does not
26+
# exist - failing this test for the one hour a day CI happens to run in that window. Same
27+
# trap, same fix as PR #4998 for the multi-car IOG tests.
28+
today = my_predbat.midnight_utc.strftime("%Y-%m-%d")
29+
tomorrow = (my_predbat.midnight_utc + timedelta(days=1)).strftime("%Y-%m-%d")
2430
tz_offset = int(my_predbat.midnight_utc.tzinfo.utcoffset(my_predbat.midnight_utc).total_seconds() / 3600)
2531
tz_offset = f"{tz_offset:02d}"
2632

0 commit comments

Comments
 (0)