Skip to content

Commit d1fccfb

Browse files
committed
Fail fast if the database doesn't support transactions.
This also fixes Django 1.6, as it tries to run connection.features.supports_transactions after our Atomic.__enter__, and it fails.
1 parent 3177981 commit d1fccfb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pytest_django/fixtures.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def shared_db_wrapper(_django_db_setup, _django_cursor_wrapper):
205205
This fixture provides a context manager that let's you access the database
206206
from a transaction spanning multiple tests.
207207
"""
208-
from django.db import transaction
208+
from django.db import connection, transaction
209+
209210
if get_django_version() < (1, 6):
210211
raise Exception('shared_db_wrapper is only supported on Django >= 1.6.')
211212

@@ -220,6 +221,10 @@ def wrapper(request):
220221
raise Exception(
221222
'shared_db_wrapper cannot be used with `transactional_db`.')
222223

224+
with _django_cursor_wrapper:
225+
if not connection.features.supports_transactions:
226+
raise Exception("Database doesn't support transactions.")
227+
223228
exc_type, exc_value, traceback = DummyException, DummyException(), None
224229
# Use atomic instead of calling .savepoint* directly.
225230
# This way works for both top-level transactions and "subtransactions".

0 commit comments

Comments
 (0)