Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.7.x] Fixed #22487: Don't flush out data from before normal TestCases

  • Loading branch information...
commit 0dd737a719cfbd3bc11ff6f2b90161883fcebea0 1 parent 68b89f4
@andrewgodwin andrewgodwin authored
View
12 django/core/management/commands/migrate.py
@@ -129,6 +129,18 @@ def handle(self, *args, **options):
else:
created_models = []
+ # The test runner requires us to flush after a syncdb but before migrations,
+ # so do that here.
+ if options.get("test_flush", False):
+ call_command(
+ 'flush',
+ verbosity=max(self.verbosity - 1, 0),
+ interactive=False,
+ database=db,
+ reset_sequences=False,
+ inhibit_post_migrate=True,
+ )
+
# Migrate!
if self.verbosity >= 1:
self.stdout.write(self.style.MIGRATE_HEADING("Running migrations:"))
View
9 django/db/backends/creation.py
@@ -371,6 +371,7 @@ def create_test_db(self, verbosity=1, autoclobber=False, serialize=True):
interactive=False,
database=self.connection.alias,
test_database=True,
+ test_flush=True,
)
# We then serialize the current state of the database into a string
@@ -380,14 +381,6 @@ def create_test_db(self, verbosity=1, autoclobber=False, serialize=True):
if serialize:
self.connection._test_serialized_contents = self.serialize_db_to_string()
- # Finally, we flush the database to clean
- call_command(
- 'flush',
- verbosity=max(verbosity - 1, 0),
- interactive=False,
- database=self.connection.alias
- )
-
call_command('createcachetable', database=self.connection.alias)
# Ensure a connection for the side effect of initializing the test database.
View
15 tests/migration_test_data_persistence/tests.py
@@ -1,11 +1,11 @@
-from django.test import TransactionTestCase
+from django.test import TransactionTestCase, TestCase
from .models import Book
class MigrationDataPersistenceTestCase(TransactionTestCase):
"""
Tests that data loaded in migrations is available if we set
- serialized_rollback = True.
+ serialized_rollback = True on TransactionTestCase
"""
available_apps = ["migration_test_data_persistence"]
@@ -18,16 +18,13 @@ def test_persistence(self):
)
-class MigrationDataNoPersistenceTestCase(TransactionTestCase):
+class MigrationDataNormalPersistenceTestCase(TestCase):
"""
- Tests the failure case
+ Tests that data loaded in migrations is available on TestCase
"""
- available_apps = ["migration_test_data_persistence"]
- serialized_rollback = False
-
- def test_no_persistence(self):
+ def test_persistence(self):
self.assertEqual(
Book.objects.count(),
- 0,
+ 1,
)
Please sign in to comment.
Something went wrong with that request. Please try again.