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 committed Mar 2, 2021
1 parent 59fdb49 commit 89ebc17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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
8 changes: 8 additions & 0 deletions tests/test_fixtures.py
Expand Up @@ -57,6 +57,14 @@ def test_admin_client_no_db_marker(admin_client):
assert force_str(resp.content) == "You are an admin"


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


# For test below.
@pytest.fixture
def existing_admin_user(django_user_model):
Expand Down

0 comments on commit 89ebc17

Please sign in to comment.