Skip to content

Commit 9817e4d

Browse files
committed
Remove leftover Django < 3.2 support
1 parent 5616b04 commit 9817e4d

File tree

3 files changed

+7
-42
lines changed

3 files changed

+7
-42
lines changed

pytest_django/fixtures.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
import os
33
from contextlib import contextmanager
44
from functools import partial
5-
from typing import (
6-
Any, Callable, Generator, Iterable, List, Optional, Tuple, Union,
7-
)
5+
from typing import Any, Generator, Iterable, List, Optional, Tuple, Union
86

97
import pytest
108

119
from . import live_server_helper
1210
from .django_compat import is_django_unittest
13-
from .lazy_django import get_django_version, skip_if_no_django
11+
from .lazy_django import skip_if_no_django
1412

1513

1614
TYPE_CHECKING = False
@@ -216,12 +214,12 @@ class PytestDjangoTestCase(test_case_class): # type: ignore[misc,valid-type]
216214
@classmethod
217215
def setUpClass(cls) -> None:
218216
super(django.test.TestCase, cls).setUpClass()
219-
if (3, 2) <= VERSION < (4, 1):
217+
if VERSION < (4, 1):
220218
django.db.transaction.Atomic._ensure_durability = False
221219

222220
@classmethod
223221
def tearDownClass(cls) -> None:
224-
if (3, 2) <= VERSION < (4, 1):
222+
if VERSION < (4, 1):
225223
django.db.transaction.Atomic._ensure_durability = True
226224
super(django.test.TestCase, cls).tearDownClass()
227225

@@ -616,36 +614,8 @@ def django_assert_max_num_queries(pytestconfig):
616614
return partial(_assert_num_queries, pytestconfig, exact=False)
617615

618616

619-
@contextmanager
620-
def _capture_on_commit_callbacks(
621-
*,
622-
using: Optional[str] = None,
623-
execute: bool = False
624-
):
625-
from django.db import DEFAULT_DB_ALIAS, connections
626-
from django.test import TestCase
627-
628-
if using is None:
629-
using = DEFAULT_DB_ALIAS
630-
631-
# Polyfill of Django code as of Django 3.2.
632-
if get_django_version() < (3, 2):
633-
callbacks: List[Callable[[], Any]] = []
634-
start_count = len(connections[using].run_on_commit)
635-
try:
636-
yield callbacks
637-
finally:
638-
run_on_commit = connections[using].run_on_commit[start_count:]
639-
callbacks[:] = [func for sids, func in run_on_commit]
640-
if execute:
641-
for callback in callbacks:
642-
callback()
643-
644-
else:
645-
with TestCase.captureOnCommitCallbacks(using=using, execute=execute) as callbacks:
646-
yield callbacks
647-
648-
649617
@pytest.fixture(scope="function")
650618
def django_capture_on_commit_callbacks():
651-
return _capture_on_commit_callbacks
619+
from django.test import TestCase
620+
621+
return TestCase.captureOnCommitCallbacks

tests/test_database.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from django.db import connection, transaction
33

4-
from pytest_django.lazy_django import get_django_version
54
from pytest_django_test.app.models import Item, SecondItem
65

76

@@ -194,7 +193,6 @@ def test_fin(self, fin: None) -> None:
194193
# Check finalizer has db access (teardown will fail if not)
195194
pass
196195

197-
@pytest.mark.skipif(get_django_version() < (3, 2), reason="Django >= 3.2 required")
198196
def test_durable_transactions(self, all_dbs: None) -> None:
199197
with transaction.atomic(durable=True):
200198
item = Item.objects.create(name="foo")

tests/test_fixtures.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from django.test.client import Client, RequestFactory
1717
from django.utils.encoding import force_str
1818

19-
from pytest_django.lazy_django import get_django_version
2019
from pytest_django_test.app.models import Item
2120

2221

@@ -36,7 +35,6 @@ def test_client(client) -> None:
3635
assert isinstance(client, Client)
3736

3837

39-
@pytest.mark.skipif(get_django_version() < (3, 1), reason="Django >= 3.1 required")
4038
def test_async_client(async_client) -> None:
4139
from django.test.client import AsyncClient
4240

@@ -85,7 +83,6 @@ def test_rf(rf) -> None:
8583
assert isinstance(rf, RequestFactory)
8684

8785

88-
@pytest.mark.skipif(get_django_version() < (3, 1), reason="Django >= 3.1 required")
8986
def test_async_rf(async_rf) -> None:
9087
from django.test.client import AsyncRequestFactory
9188

0 commit comments

Comments
 (0)