File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import logging
44import time
55import timeit
6- from datetime import datetime
6+ from datetime import datetime , timezone
77
88import freezegun
99import pytest
@@ -37,10 +37,11 @@ def small_interval(monkeypatch) -> None:
3737
3838@pytest .fixture (autouse = True )
3939def sleep_faster (monkeypatch ):
40- # The timezone offset in seconds, add 10 seconds to make sure we don't
41- # accidentally get the wrong hour
42- offset_seconds = (datetime .now () - datetime .utcnow ()).seconds + 10
43- offset_hours = int (offset_seconds / 3600 )
40+ # Compute the local UTC offset so freezegun uses the same timezone as
41+ # the local system. Using datetime.now(timezone.utc).astimezone() avoids
42+ # the deprecated datetime.utcnow() which was removed in Python 3.12+.
43+ local_offset = datetime .now (timezone .utc ).astimezone ().utcoffset ()
44+ offset_hours = local_offset .total_seconds () / 3600
4445
4546 freeze_time = freezegun .freeze_time (tz_offset = offset_hours )
4647 with freeze_time as fake_time :
You can’t perform that action at this time.
0 commit comments