Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Prevented TestNoInitialDataLoading to pollute other tests (Refs #15926)

Tests were still failing with MySQL. It seems a rollback is solving
the issue.
  • Loading branch information...
commit 2c57809a560cb67c79b9e8a77cc713e8a2424c8e 1 parent f5ce179
@claudep claudep authored
Showing with 22 additions and 16 deletions.
  1. +22 −16 tests/modeltests/fixtures_model_package/tests.py
View
38 tests/modeltests/fixtures_model_package/tests.py
@@ -1,5 +1,6 @@
from django.core import management
-from django.test import TestCase
+from django.db import transaction
+from django.test import TestCase, TransactionTestCase
from .models import Article, Book
@@ -20,16 +21,18 @@ def testClassFixtures(self):
)
-class TestNoInitialDataLoading(TestCase):
+class TestNoInitialDataLoading(TransactionTestCase):
def test_syncdb(self):
- Book.objects.all().delete()
+ with transaction.commit_manually():
+ Book.objects.all().delete()
- management.call_command(
- 'syncdb',
- verbosity=0,
- load_initial_data=False
- )
- self.assertQuerysetEqual(Book.objects.all(), [])
+ management.call_command(
+ 'syncdb',
+ verbosity=0,
+ load_initial_data=False
+ )
+ self.assertQuerysetEqual(Book.objects.all(), [])
+ transaction.rollback()
def test_flush(self):
# Test presence of fixture (flush called by TransactionTestCase)
@@ -40,13 +43,16 @@ def test_flush(self):
lambda a: a.name
)
- management.call_command(
- 'flush',
- verbosity=0,
- interactive=False,
- load_initial_data=False
- )
- self.assertQuerysetEqual(Book.objects.all(), [])
+ with transaction.commit_manually():
+ management.call_command(
+ 'flush',
+ verbosity=0,
+ interactive=False,
+ commit=False,
+ load_initial_data=False
+ )
+ self.assertQuerysetEqual(Book.objects.all(), [])
+ transaction.rollback()
class FixtureTestCase(TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.