Skip to content

Commit 178b5e2

Browse files
committed
Always use a TestCase subclass
This is more flexible/orthogonal.
1 parent d42ab3b commit 178b5e2

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

pytest_django/fixtures.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,28 @@ def _django_db_fixture_helper(
145145
django_db_blocker.unblock()
146146
request.addfinalizer(django_db_blocker.restore)
147147

148+
import django.test
149+
import django.db
150+
148151
if transactional:
149-
from django.test import TransactionTestCase as django_case
152+
test_case_class = django.test.TransactionTestCase
153+
else:
154+
test_case_class = django.test.TestCase
150155

151-
if reset_sequences:
156+
_reset_sequences = reset_sequences
152157

153-
class ResetSequenceTestCase(django_case):
154-
reset_sequences = True
158+
class PytestDjangoTestCase(test_case_class): # type: ignore[misc,valid-type]
159+
if transactional and _reset_sequences:
160+
reset_sequences = True
155161

156-
django_case = ResetSequenceTestCase
157-
else:
158-
from django.test import TestCase as django_case
159-
from django.db import transaction
160-
transaction.Atomic._ensure_durability = False
162+
if not transactional:
163+
django.db.transaction.Atomic._ensure_durability = False
161164

162165
def reset_durability() -> None:
163-
transaction.Atomic._ensure_durability = True
166+
django.db.transaction.Atomic._ensure_durability = True
164167
request.addfinalizer(reset_durability)
165168

166-
test_case = django_case(methodName="__init__")
169+
test_case = PytestDjangoTestCase(methodName="__init__")
167170
test_case._pre_setup()
168171
request.addfinalizer(test_case._post_teardown)
169172

0 commit comments

Comments
 (0)