Replace dateutil with zoneinfo in test.tz_stub
MODIFY
dev-requirements.txt
dev-requirements.txt
@@ -7,7 +7,7 @@ pytest-freezegun==0.4.2
flaky==3.7.0
trustme==0.9.0
cryptography==3.4.7
-python-dateutil==2.8.1
requests
+backports.zoneinfo==0.2.1;python_version<"3.9"
# https://github.com/twisted/towncrier/pull/356
git+https://github.com/pquentin/towncrier.git@stop-writing-title-twice

MODIFY
mypy-requirements.txt
mypy-requirements.txt
@@ -4,5 +4,5 @@ cryptography>=1.3.4
tornado>=6.1
pytest>=6.2
trustme==0.9.0
-types-python-dateutil
+types-backports
nox

MODIFY
test/tz_stub.py
test/tz_stub.py
@@ -5,7 +5,12 @@ from contextlib import contextmanager
from typing import Generator, Optional
import pytest
-from dateutil import tz
+
+try:
+ import zoneinfo # type: ignore[import]
+except ImportError:
+ # Python < 3.9
+ from backports import zoneinfo # type: ignore[no-redef]
@contextmanager
@@ -23,17 +28,16 @@ def stub_timezone_ctx(tzname: Optional[str]) -> Generator[None, None, None]:
if not hasattr(time, "tzset"):
pytest.skip("Timezone patching is not supported")
- # Make sure the new timezone exists, at least in dateutil
- new_tz = tz.gettz(tzname)
- if new_tz is None:
+ # Make sure the new timezone exists
+ try:
+ zoneinfo.ZoneInfo(tzname)
+ except zoneinfo.ZoneInfoNotFoundError:
raise ValueError(f"Invalid timezone specified: {tzname!r}")
# Get the current timezone
- local_tz = tz.tzlocal()
- if local_tz is None:
+ old_tzname = datetime.datetime.now().astimezone().tzname()
+ if old_tzname is None:
raise OSError("Cannot determine current timezone")
- old_tzname = datetime.datetime.now(local_tz).tzname()
- assert old_tzname is not None
os.environ["TZ"] = tzname
time.tzset()

Replace dateutil with zoneinfo in test.tz_stub