From ada83fd8b89ab194194c9069eef4d6ee6cbec0ee Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 23 Dec 2020 07:48:45 +0100 Subject: [PATCH] Fixed isolation of test_migrate_fake_split_initial. --- tests/migrations/test_commands.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 79dd95133c92..da9a571e8a95 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -229,18 +229,20 @@ def test_migrate_fake_split_initial(self): """ Split initial migrations can be faked with --fake-initial. """ - call_command("migrate", "migrations", "0002", verbosity=0) - call_command("migrate", "migrations", "zero", fake=True, verbosity=0) - out = io.StringIO() - with mock.patch('django.core.management.color.supports_color', lambda *args: False): - call_command("migrate", "migrations", "0002", fake_initial=True, stdout=out, verbosity=1) - value = out.getvalue().lower() - self.assertIn("migrations.0001_initial... faked", value) - self.assertIn("migrations.0002_second... faked", value) - # Fake an apply - call_command("migrate", "migrations", fake=True, verbosity=0) - # Unmigrate everything - call_command("migrate", "migrations", "zero", verbosity=0) + try: + call_command('migrate', 'migrations', '0002', verbosity=0) + call_command('migrate', 'migrations', 'zero', fake=True, verbosity=0) + out = io.StringIO() + with mock.patch('django.core.management.color.supports_color', lambda *args: False): + call_command('migrate', 'migrations', '0002', fake_initial=True, stdout=out, verbosity=1) + value = out.getvalue().lower() + self.assertIn('migrations.0001_initial... faked', value) + self.assertIn('migrations.0002_second... faked', value) + finally: + # Fake an apply. + call_command('migrate', 'migrations', fake=True, verbosity=0) + # Unmigrate everything. + call_command('migrate', 'migrations', 'zero', verbosity=0) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"}) def test_migrate_conflict_exit(self):