Skip to content

Commit b38f7f5

Browse files
authored
Merge pull request #307 from wolph/copilot/fix-deprecation-warning-date-parsing
2 parents 24cfd2e + 9c963ea commit b38f7f5

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

tests/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import time
55
import timeit
6-
from datetime import datetime
6+
from datetime import datetime, timezone
77

88
import freezegun
99
import pytest
@@ -37,10 +37,11 @@ def small_interval(monkeypatch) -> None:
3737

3838
@pytest.fixture(autouse=True)
3939
def 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() (deprecated since 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:

0 commit comments

Comments
 (0)