Fix test with Django 5 when pytz is available (#9715)

* Fix test with Django 5 when pytz is available

* fix formatting

* remove original condition

Co-authored-by: Ülgen Sarıkavak <ulgens@users.noreply.github.com>

* remove trailing whitespace

* further improvements

* let's not skip the pytz test - it should always be executed when testing against Django 4

* add comment to test requirements

Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>

* simplify the pytz import as it should always be available

* make isort happy

---------

Co-authored-by: Ülgen Sarıkavak <ulgens@users.noreply.github.com>
Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
This commit is contained in:
Jakub Kulík 2025-07-24 09:47:47 +02:00 committed by GitHub
parent 2ae8c117da
commit 853969c69c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 15 deletions

View File

@ -5,3 +5,4 @@ pytest-django>=4.5.2,<5.0
importlib-metadata<5.0
# temporary pin of attrs
attrs==22.1.0
pytz # Remove when dropping support for Django<5.0

View File

@ -9,13 +9,9 @@ from enum import auto
from unittest.mock import patch
from zoneinfo import ZoneInfo
import django
import pytest
try:
import pytz
except ImportError:
pytz = None
import pytz
from django.core.exceptions import ValidationError as DjangoValidationError
from django.db.models import IntegerChoices, TextChoices
from django.http import QueryDict
@ -1624,7 +1620,10 @@ class TestCustomTimezoneForDateTimeField(TestCase):
assert rendered_date == rendered_date_in_timezone
@pytest.mark.skipif(pytz is None, reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.")
@pytest.mark.skipif(
condition=django.VERSION >= (5,),
reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.",
)
class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
"""
Invalid values for `DateTimeField` with datetime in DST shift (non-existing or ambiguous) and timezone with DST.
@ -1638,7 +1637,6 @@ class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
}
outputs = {}
if pytz:
class MockTimezone(pytz.BaseTzInfo):
@staticmethod
def localize(value, is_dst):