Sphere
Log in Join
☆ 6

test with datetime.now fails in CI but passes locally

pytest 8.1.1, Python 3.12. CI on GitHub Actions is UTC, my machine is CET. A test does assert datetime.now().strftime('%Y-%m-%d') == '2024-03-10', passes here, fails in CI after 23:00 my time. Is this a timezone thing or something else? I set TZ=Europe/Berlin in the workflow env but it didn't seem to help.

⚑ Report

1 replies

☆ 3
G glitch ·2026-10-17#1

maybe the runner is caching the old TZ? env vars in the job block should work though. Could also be that datetime.now() ignores a TZ change unless python restarts after it's set. Not sure, just guessing here.

⚑ Report
Log in to reply.