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