Skip to content

Commit c6cfc6b

Browse files
committed
Update Django versions
1 parent 750f7b1 commit c6cfc6b

File tree

9 files changed

+38
-13
lines changed

9 files changed

+38
-13
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ jobs:
4444
- lint-conjecture-rust
4545
- check-nose
4646
- check-pytest46
47+
- check-django40
4748
- check-django32
48-
- check-django31
4949
- check-django22
5050
- check-pandas13
5151
- check-pandas12

hypothesis-python/RELEASE.rst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RELEASE_TYPE: minor
2+
3+
This release makes us compatible with :pypi:`Django` 4.0, in particular by adding
4+
support for use of :mod:`zoneinfo` timezones (though we respect the new
5+
``USE_DEPRECATED_PYTZ`` setting if you need it).

hypothesis-python/docs/supported.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ In terms of what's actually *known* to work:
7979
and avoid poor interactions with Pytest fixtures.
8080
* Nose works fine with Hypothesis, and this is tested as part of the CI. ``yield`` based
8181
tests simply won't work.
82-
* Integration with Django's testing requires use of the :ref:`hypothesis-django` package.
82+
* Integration with Django's testing requires use of the :ref:`hypothesis-django` extra.
8383
The issue is that in Django's tests' normal mode of execution it will reset the
8484
database once per test rather than once per example, which is not what you want.
8585
* :pypi:`Coverage` works out of the box with Hypothesis; our own test suite has

hypothesis-python/setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def local_file(name):
7777
],
7878
# We only support Django versions with upstream support - see
7979
# https://www.djangoproject.com/download/#supported-versions
80-
"django": ["pytz>=2014.1", "django>=2.2"],
80+
# We also leave the choice of timezone library to the user, since it
81+
# might be zoneinfo or pytz depending on version and configuration.
82+
"django": ["django>=2.2"],
8183
}
8284

8385
extras["all"] = sorted(

hypothesis-python/src/hypothesis/extra/django/_fields.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import string
1818
from datetime import timedelta
1919
from decimal import Decimal
20+
from functools import lru_cache
2021
from typing import Any, Callable, Dict, Type, TypeVar, Union
2122

2223
import django
@@ -30,7 +31,6 @@
3031

3132
from hypothesis import strategies as st
3233
from hypothesis.errors import InvalidArgument, ResolutionFailed
33-
from hypothesis.extra.pytz import timezones
3434
from hypothesis.internal.validation import check_type
3535
from hypothesis.provisional import urls
3636
from hypothesis.strategies import emails
@@ -57,6 +57,18 @@ def inner(field):
5757
return inner
5858

5959

60+
@lru_cache()
61+
def timezones():
62+
# From Django 4.0, the default is to use zoneinfo instead of pytz.
63+
assert getattr(django.conf.settings, "USE_TZ", False)
64+
if getattr(django.conf.settings, "USE_DEPRECATED_PYTZ", True):
65+
from hypothesis.extra.pytz import timezones
66+
else:
67+
from hypothesis.strategies import timezones
68+
69+
return timezones()
70+
71+
6072
# Mapping of field types, to strategy objects or functions of (type) -> strategy
6173
_FieldLookUpType = Dict[
6274
Type[AnyField],

hypothesis-python/tests/django/manage.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@
3838
warnings.simplefilter("ignore", category=DeprecationWarning)
3939
from django.core.management import execute_from_command_line
4040

41-
execute_from_command_line(sys.argv)
41+
try:
42+
from django.utils.deprecation import RemovedInDjango50Warning
43+
except ImportError:
44+
RemovedInDjango50Warning = ()
45+
46+
with warnings.catch_warnings():
47+
warnings.simplefilter("ignore", category=RemovedInDjango50Warning)
48+
execute_from_command_line(sys.argv)

hypothesis-python/tests/django/toys/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#
1414
# END HEADER
1515

16-
from django.conf.urls import include, re_path
1716
from django.contrib import admin
17+
from django.urls import include, re_path
1818

1919
patterns, namespace, name = admin.site.urls
2020

hypothesis-python/tox.ini

+5-6
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,18 @@ commands =
8383
[testenv:django22]
8484
commands =
8585
pip install .[pytz]
86-
pip install django~=2.2.24
86+
pip install django~=2.2.25
8787
python -m tests.django.manage test tests.django
8888

89-
[testenv:django31]
89+
[testenv:django32]
9090
commands =
9191
pip install .[pytz]
92-
pip install django~=3.1.13
92+
pip install django~=3.2.10
9393
python -m tests.django.manage test tests.django
9494

95-
[testenv:django32]
95+
[testenv:django40]
9696
commands =
97-
pip install .[pytz]
98-
pip install django~=3.2.9
97+
pip install django~=4.0.0
9998
python -m tests.django.manage test tests.django
10099

101100
[testenv:nose]

tooling/src/hypothesistooling/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def standard_tox_task(name):
475475
standard_tox_task("nose")
476476
standard_tox_task("pytest46")
477477

478-
for n in [22, 31, 32]:
478+
for n in [22, 32, 40]:
479479
standard_tox_task(f"django{n}")
480480
for n in [25, 10, 11, 12, 13]:
481481
standard_tox_task(f"pandas{n}")

0 commit comments

Comments
 (0)