| 1 |
import pytest |
| 2 |
|
| 3 |
try: |
| 4 |
import zoneinfo |
| 5 |
except ModuleNotFoundError: |
| 6 |
try: |
| 7 |
from backports import zoneinfo |
| 8 |
except ImportError: |
| 9 |
zoneinfo = None |
| 10 |
|
| 11 |
try: |
| 12 |
import pytz |
| 13 |
except ModuleNotFoundError: |
| 14 |
pytz = None |
| 15 |
|
| 16 |
|
| 17 |
def pytest_generate_tests(metafunc): |
| 18 |
if hasattr(metafunc.function, "pytestmark"): |
| 19 |
for mark in metafunc.function.pytestmark: |
| 20 |
if mark.name == "all_locales": |
| 21 |
from babel.localedata import locale_identifiers |
| 22 |
metafunc.parametrize("locale", list(locale_identifiers())) |
| 23 |
break |
| 24 |
|
| 25 |
|
| 26 |
@pytest.fixture(params=["pytz.timezone", "zoneinfo.ZoneInfo"], scope="package") |
| 27 |
def timezone_getter(request): |
| 28 |
if request.param == "pytz.timezone": |
| 29 |
if pytz: |
| 30 |
return pytz.timezone |
| 31 |
else: |
| 32 |
pytest.skip("pytz not available") |
| 33 |
elif request.param == "zoneinfo.ZoneInfo": |
| 34 |
if zoneinfo: |
| 35 |
return zoneinfo.ZoneInfo |
| 36 |
else: |
| 37 |
pytest.skip("zoneinfo not available") |
| 38 |
else: |
| 39 |
raise NotImplementedError |