@@ -182,6 +182,32 @@ class PytestDjangoTestCase(test_case_class): # type: ignore[misc,valid-type]
182
182
if _databases is not None :
183
183
databases = _databases
184
184
185
+ # For non-transactional tests, skip executing `django.test.TestCase`'s
186
+ # `setUpClass`/`tearDownClass`, only execute the super class ones.
187
+ #
188
+ # `TestCase`'s class setup manages the `setUpTestData`/class-level
189
+ # transaction functionality. We don't use it; instead we (will) offer
190
+ # our own alternatives. So it only adds overhead, and does some things
191
+ # which conflict with our (planned) functionality, particularly, it
192
+ # closes all database connections in `tearDownClass` which inhibits
193
+ # wrapping tests in higher-scoped transactions.
194
+ #
195
+ # It's possible a new version of Django will add some unrelated
196
+ # functionality to these methods, in which case skipping them completely
197
+ # would not be desirable. Let's cross that bridge when we get there...
198
+ if not transactional :
199
+ @classmethod
200
+ def setUpClass (cls ) -> None :
201
+ super (django .test .TestCase , cls ).setUpClass ()
202
+ if (3 , 2 ) <= VERSION < (4 , 0 ):
203
+ django .db .transaction .Atomic ._ensure_durability = False
204
+
205
+ @classmethod
206
+ def tearDownClass (cls ) -> None :
207
+ if (3 , 2 ) <= VERSION < (4 , 0 ):
208
+ django .db .transaction .Atomic ._ensure_durability = True
209
+ super (django .test .TestCase , cls ).tearDownClass ()
210
+
185
211
PytestDjangoTestCase .setUpClass ()
186
212
if VERSION >= (4 , 0 ):
187
213
request .addfinalizer (PytestDjangoTestCase .doClassCleanups )
0 commit comments