@@ -64,34 +64,44 @@ def _django_db_fixture_helper(transactional, request, _django_cursor_wrapper):
64
64
if is_django_unittest (request ):
65
65
return
66
66
67
+ if not transactional and 'live_server' in request .funcargnames :
68
+ # Do nothing, we get called with transactional=True, too.
69
+ return
70
+
71
+ django_case = None
72
+
73
+ _django_cursor_wrapper .enable ()
74
+ request .addfinalizer (_django_cursor_wrapper .disable )
75
+
67
76
if transactional :
68
- _django_cursor_wrapper .enable ()
69
-
70
- def flushdb ():
71
- """Flush the database and close database connections"""
72
- # Django does this by default *before* each test
73
- # instead of after.
74
- from django .db import connections
75
- from django .core .management import call_command
76
-
77
- for db in connections :
78
- call_command ('flush' , verbosity = 0 ,
79
- interactive = False , database = db )
80
- for conn in connections .all ():
81
- conn .close ()
82
-
83
- request .addfinalizer (_django_cursor_wrapper .disable )
84
- request .addfinalizer (flushdb )
77
+ from django import get_version
78
+
79
+ if get_version () >= '1.5' :
80
+ from django .test import TransactionTestCase as django_case
81
+
82
+ else :
83
+ # Django before 1.5 flushed the DB during setUp.
84
+ # Use pytest-django's old behavior with it.
85
+ def flushdb ():
86
+ """Flush the database and close database connections"""
87
+ # Django does this by default *before* each test
88
+ # instead of after.
89
+ from django .db import connections
90
+ from django .core .management import call_command
91
+
92
+ for db in connections :
93
+ call_command ('flush' , verbosity = 0 ,
94
+ interactive = False , database = db )
95
+ for conn in connections .all ():
96
+ conn .close ()
97
+ request .addfinalizer (flushdb )
98
+
85
99
else :
86
- if 'live_server' in request .funcargnames :
87
- return
88
- from django .test import TestCase
100
+ from django .test import TestCase as django_case
89
101
90
- _django_cursor_wrapper .enable ()
91
- _django_cursor_wrapper ._is_transactional = False
92
- case = TestCase (methodName = '__init__' )
102
+ if django_case :
103
+ case = django_case (methodName = '__init__' )
93
104
case ._pre_setup ()
94
- request .addfinalizer (_django_cursor_wrapper .disable )
95
105
request .addfinalizer (case ._post_teardown )
96
106
97
107
0 commit comments