diff options
| author | Tim Graham <timograham@gmail.com> | 2018-12-05 15:21:09 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-12-05 15:30:23 -0500 |
| commit | 4c7c608a1deee37055d4a2b8a71e34def04a2a1f (patch) | |
| tree | f1bd8c1300f3ece897fd22b6820987460f014f84 /django | |
| parent | 734ce71824180740f2318750ae2436f4b60c30b1 (diff) | |
Reverted "Fixed #25251 -- Made data migrations available in TransactionTestCase when using --keepdb."
This reverts commits b3b1d3d45fc066367f4fcacf0b06f72fcd00a9c6 and
9fa0d3786febf36c87ef059a39115aa1ce3326e8 due to reverse build failures
for which a solution isn't forthcoming.
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/runner.py | 27 | ||||
| -rw-r--r-- | django/test/testcases.py | 28 |
2 files changed, 13 insertions, 42 deletions
diff --git a/django/test/runner.py b/django/test/runner.py index 7dc28587af..ed969cc42f 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -11,7 +11,7 @@ from io import StringIO from django.core.management import call_command from django.db import connections -from django.test import SimpleTestCase, TestCase, TransactionTestCase +from django.test import SimpleTestCase, TestCase from django.test.utils import ( setup_databases as _setup_databases, setup_test_environment, teardown_databases as _teardown_databases, teardown_test_environment, @@ -399,7 +399,7 @@ class DiscoverRunner: parallel_test_suite = ParallelTestSuite test_runner = unittest.TextTestRunner test_loader = unittest.defaultTestLoader - reorder_by = (TestCase, TransactionTestCase, SimpleTestCase) + reorder_by = (TestCase, SimpleTestCase) def __init__(self, pattern=None, top_level=None, verbosity=1, interactive=True, failfast=False, keepdb=False, @@ -637,27 +637,6 @@ def is_discoverable(label): return os.path.isdir(os.path.abspath(label)) -def reorder_postprocess(reordered_suite): - """ - To make TransactionTestCases initialize their data properly, they must know - if the next TransactionTestCase needs initial data migrations serialized in - the connection. Initialize _next_serialized_rollback attribute depending on - the serialized_rollback option present in the next test class in the suite. - If the next test has no serialized_rollback attribute, it means there - aren't any more TransactionTestCases. - """ - # Filter out skipped tests. - active_tests = [ - test for test in reordered_suite._tests - if not getattr(test, '__unittest_skip__', False) - ] - for previous_test, next_test in zip(active_tests[:-1], active_tests[1:]): - next_serialized_rollback = getattr(next_test, 'serialized_rollback', None) - if next_serialized_rollback is not None: - previous_test._next_serialized_rollback = next_serialized_rollback - return reordered_suite - - def reorder_suite(suite, classes, reverse=False): """ Reorder a test suite by test type. @@ -677,7 +656,7 @@ def reorder_suite(suite, classes, reverse=False): reordered_suite = suite_class() for i in range(class_count + 1): reordered_suite.addTests(bins[i]) - return reorder_postprocess(reordered_suite) + return reordered_suite def partition_suite_by_type(suite, classes, bins, reverse=False): diff --git a/django/test/testcases.py b/django/test/testcases.py index 9f549f626f..36986185ce 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -827,15 +827,6 @@ class TransactionTestCase(SimpleTestCase): # This can be slow; this flag allows enabling on a per-case basis. serialized_rollback = False - # This attribute is strongly linked to serialized_rollback parameter and - # allows the data restoration after the database flush, at the end of the - # test, if the next test needs the initial data. This attribute is updated - # by the test runner when the test suite is built. Being initialized to - # True is crucial: the last TransactionTestCase, which doesn't have any - # test classes with the serialized_rollback attribute, will always have - # this value set to True. - _next_serialized_rollback = True - # Since tests will be wrapped in a transaction, or serialized if they # are not available, we allow queries to be run. allow_database_queries = True @@ -906,6 +897,16 @@ class TransactionTestCase(SimpleTestCase): if self.reset_sequences: self._reset_sequences(db_name) + # Provide replica initial data from migrated apps, if needed. + 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. @@ -959,15 +960,6 @@ class TransactionTestCase(SimpleTestCase): database=db_name, reset_sequences=False, allow_cascade=self.available_apps is not None, inhibit_post_migrate=inhibit_post_migrate) - # Provide replica initial data from migrated apps, if needed. - if self._next_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 = map(transform, qs) |
