diff --git a/django_dump_die/constants.py b/django_dump_die/constants.py index 190b827b0397797ba51f8b8abcf09e351f21ffec..89b54836613b3614d73ff1ae7d16c1dbe70180d5 100644 --- a/django_dump_die/constants.py +++ b/django_dump_die/constants.py @@ -2,20 +2,26 @@ import datetime import types -try: - from zoneinfo import ZoneInfo - ZONEINFO_PRESENT = True -except ImportError: - ZONEINFO_PRESENT = False from decimal import Decimal - from django.conf import settings from django.forms.boundfield import BoundField from django.utils import timezone from pathlib import PosixPath, PurePath, PurePosixPath, PureWindowsPath +# Imports that may not be accessible, depending on local python environment setup. +try: + from zoneinfo import ZoneInfo + ZONEINFO_PRESENT = True +except ImportError: + ZONEINFO_PRESENT = False +try: + import pytz + PYTZ_PRESENT = True +except ImportError: + PYTZ_PRESENT = False + # Simple types that do not need to be recursively inspected. SIMPLE_TYPES = [ diff --git a/tests/test_views.py b/tests/test_views.py index b948195e48ba266197d7a19ee55485d0d52fd7b8..796a495f44c3d900ccaf1b3f27dee8fbebfff48f 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,12 +1,16 @@ import datetime import os +import unittest + from django.test import override_settings from django.utils import timezone from django_expanded_test_cases import IntegrationTestCase from freezegun import freeze_time from unittest.mock import patch +from django_dump_die.constants import PYTZ_PRESENT, ZONEINFO_PRESENT + # Set datetime for freezegun and template render comparison. # Ensures that seconds,etc match exactly for what is rendered vs what we check. @@ -1762,6 +1766,7 @@ class DumpDieIntermediateTypeTestCase(GenericViewTestCase): content_ends_before='sample_pytz_timezone', ) + @unittest.skipIf(not PYTZ_PRESENT, 'Pytz not present. Likely Django >= 4.0.') @patch('django_dump_die.templatetags.dump_die._generate_unique') def test_pytz_timezone_display(self, mocked_unique_generation): """Verify dumping a "pytz timezone" type has expected output.""" @@ -1850,6 +1855,7 @@ class DumpDieIntermediateTypeTestCase(GenericViewTestCase): content_ends_before='sample_zoneinfo_timezone', ) + @unittest.skipIf(not ZONEINFO_PRESENT, 'ZoneInfo not present. Likely Python < 3.9.') @patch('django_dump_die.templatetags.dump_die._generate_unique') def test_zoneinfo_timezone_display(self, mocked_unique_generation): """Verify dumping a "zoneinfo timezone" type has expected output."""