From 90916f050c64b817fdf2ea13b5c20986005fd029 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 22 Apr 2021 17:43:58 +0200 Subject: [PATCH] Fixed isolation of test_showmigrations_unmigrated_app(). --- tests/migrations/test_commands.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 9346ba63e9a..00d4de1ff13 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -519,7 +519,15 @@ class MigrateTests(MigrationTestBase): def test_showmigrations_unmigrated_app(self): out = io.StringIO() call_command('showmigrations', 'unmigrated_app', stdout=out, no_color=True) - self.assertEqual('unmigrated_app\n (no migrations)\n', out.getvalue().lower()) + try: + self.assertEqual('unmigrated_app\n (no migrations)\n', out.getvalue().lower()) + finally: + # unmigrated_app.SillyModel has a foreign key to + # 'migrations.Tribble', but that model is only defined in a + # migration, so the global app registry never sees it and the + # reference is left dangling. Remove it to avoid problems in + # subsequent tests. + apps._pending_operations.pop(('migrations', 'tribble'), None) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_empty"}) def test_showmigrations_plan_no_migrations(self): @@ -836,7 +844,7 @@ class MigrateTests(MigrationTestBase): # but that model is only defined in a migration, so the global app # registry never sees it and the reference is left dangling. Remove it # to avoid problems in subsequent tests. - del apps._pending_operations[('migrations', 'tribble')] + apps._pending_operations.pop(('migrations', 'tribble'), None) @override_settings(INSTALLED_APPS=['migrations.migrations_test_apps.unmigrated_app_syncdb']) def test_migrate_syncdb_deferred_sql_executed_with_schemaeditor(self):