Skip to content

Commit

Permalink
Disable atomic durability check on non-transactional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hannseman authored and bluetech committed Mar 3, 2021
1 parent 762cfc2 commit edd3311
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pytest_django/fixtures.py
Expand Up @@ -147,6 +147,12 @@ class ResetSequenceTestCase(django_case):
django_case = ResetSequenceTestCase
else:
from django.test import TestCase as django_case
from django.db import transaction
transaction.Atomic._ensure_durability = False

def reset_durability():
transaction.Atomic._ensure_durability = True
request.addfinalizer(reset_durability)

test_case = django_case(methodName="__init__")
test_case._pre_setup()
Expand Down
9 changes: 8 additions & 1 deletion tests/test_database.py
@@ -1,7 +1,8 @@
import pytest
from django.db import connection
from django.db import connection, transaction
from django.test.testcases import connections_support_transactions

from pytest_django.lazy_django import get_django_version
from pytest_django_test.app.models import Item


Expand Down Expand Up @@ -138,6 +139,12 @@ def test_fin(self, fin):
# Check finalizer has db access (teardown will fail if not)
pass

@pytest.mark.skipif(get_django_version() < (3, 2), reason="Django >= 3.2 required")
def test_durable_transactions(self, all_dbs):
with transaction.atomic(durable=True):
item = Item.objects.create(name="foo")
assert Item.objects.get() == item


class TestDatabaseFixturesAllOrder:
@pytest.fixture
Expand Down

0 comments on commit edd3311

Please sign in to comment.