diff --git a/tracdb/testutils.py b/tracdb/testutils.py index 1a9698932..1d15d48cc 100644 --- a/tracdb/testutils.py +++ b/tracdb/testutils.py @@ -67,6 +67,17 @@ def create_db_tables_for_unmanaged_models(schema_editor): _create_db_table_for_model(model, schema_editor) +def destroy_db_tables_for_unmanaged_models(schema_editor): + """ + Destroy tables for all unmanaged models in the tracdb app + """ + appconfig = apps.get_app_config("tracdb") + for model in appconfig.get_models(): + if model._meta.managed: + continue + schema_editor.delete_model(model) + + class TracDBCreateDatabaseMixin: """ A TestCase mixin that creates test tables for all the tracdb apps. @@ -75,6 +86,12 @@ class TracDBCreateDatabaseMixin: @classmethod def setUpClass(cls): - super().setUpClass() with connections["trac"].schema_editor() as schema_editor: create_db_tables_for_unmanaged_models(schema_editor) + super().setUpClass() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + with connections["trac"].schema_editor() as schema_editor: + destroy_db_tables_for_unmanaged_models(schema_editor)