Permalink
Browse files

[1.8.x] Fixed #25251 -- Inconsistency in migration data with keepdb a…

…nd TransactionTestCase

Data loaded in migrations are restored at the beginning of each TransactionTestCase and all the tables are truncated at the end of these test cases.
It means that, at the end of your whole test suite, if there was at least one TransactionTestCase, the migrated data are no more in the database, specially surprising when using --keepdb option.
Now we restore data at the end of a TransactionTestCase, to be sure that the next test will be in the expected environment (data loaded from initial migrations)
  • Loading branch information...
romgar committed Feb 11, 2016
1 parent edff550 commit 7219308cf8f196463d03d1407b0ad0e9b918a3db
Showing with 10 additions and 11 deletions.
  1. +10 −11 django/test/testcases.py
View
@@ -822,17 +822,6 @@ def _fixture_setup(self):
if self.reset_sequences:
self._reset_sequences(db_name)
# If we need to provide replica initial data from migrated apps,
# then do so.
if self.serialized_rollback and hasattr(connections[db_name], "_test_serialized_contents"):
if self.available_apps is not None:
apps.unset_available_apps()
connections[db_name].creation.deserialize_db_from_string(
connections[db_name]._test_serialized_contents
)
if self.available_apps is not None:
apps.set_available_apps(self.available_apps)
if self.fixtures:
# We have to use this slightly awkward syntax due to the fact
# that we're using *args and **kwargs together.
@@ -878,6 +867,16 @@ def _fixture_teardown(self):
database=db_name, reset_sequences=False,
allow_cascade=self.available_apps is not None,
inhibit_post_migrate=self.available_apps is not None)
# If we need to provide replica initial data from migrated apps,
# then do so.
if self.serialized_rollback and hasattr(connections[db_name], "_test_serialized_contents"):
if self.available_apps is not None:
apps.unset_available_apps()
connections[db_name].creation.deserialize_db_from_string(
connections[db_name]._test_serialized_contents
)
if self.available_apps is not None:
apps.set_available_apps(self.available_apps)
def assertQuerysetEqual(self, qs, values, transform=repr, ordered=True, msg=None):
items = six.moves.map(transform, qs)

0 comments on commit 7219308

Please sign in to comment.