[1.11.x] Added isolated_local_models support to schema tests.

Follow up to 46496a542c2ff9f273e090073e9c8071acb1a4a4, which otherwise
has no effect.

Partial backport of 9f7772e098439f9edea3d25ab127539fc514eeb2 from master
This commit is contained in:
Tim Graham 2018-04-14 07:18:33 -04:00
parent f89b11b879
commit 4a20aae468

View File

@ -59,6 +59,9 @@ class SchemaTests(TransactionTestCase):
# local_models should contain test dependent model classes that will be
# automatically removed from the app cache on test tear down.
self.local_models = []
# isolated_local_models contains models that are in test methods
# decorated with @isolate_apps.
self.isolated_local_models = []
def tearDown(self):
# Delete any tables made for our models
@ -73,6 +76,10 @@ class SchemaTests(TransactionTestCase):
if through and through._meta.auto_created:
del new_apps.all_models['schema'][through._meta.model_name]
del new_apps.all_models['schema'][model._meta.model_name]
if self.isolated_local_models:
with connection.schema_editor() as editor:
for model in self.isolated_local_models:
editor.delete_model(model)
def delete_tables(self):
"Deletes all model tables for our models for a clean test environment"