From 8eba6efbf08d3fe5d64bd92948c2c86ab4f07608 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 8 Nov 2023 22:29:07 +0000 Subject: [5.0.x] Fixed #34457 -- Restored output for makemigrations --check. Co-authored-by: David Sanders Co-authored-by: Natalia <124304+nessita@users.noreply.github.com> Backport of f7389c4b07ceeb036436e065898e411b247bca78 from main --- tests/migrations/test_commands.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 387cef924a..a9c1cdf893 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -2392,20 +2392,35 @@ class MakeMigrationsTests(MigrationTestBase): "makemigrations", "migrations", "--name", "invalid name", "--empty" ) - def test_makemigrations_check(self): + def test_makemigrations_check_with_changes(self): """ makemigrations --check should exit with a non-zero status when there are changes to an app requiring migrations. """ + out = io.StringIO() with self.temporary_migration_module() as tmpdir: - with self.assertRaises(SystemExit): - call_command("makemigrations", "--check", "migrations", verbosity=0) - self.assertFalse(os.path.exists(tmpdir)) + with self.assertRaises(SystemExit) as cm: + call_command( + "makemigrations", + "--check", + "migrations", + stdout=out, + ) + self.assertEqual(os.listdir(tmpdir), ["__init__.py"]) + self.assertEqual(cm.exception.code, 1) + self.assertIn("Migrations for 'migrations':", out.getvalue()) + def test_makemigrations_check_no_changes(self): + """ + makemigrations --check should exit with a zero status when there are no + changes. + """ + out = io.StringIO() with self.temporary_migration_module( module="migrations.test_migrations_no_changes" ): - call_command("makemigrations", "--check", "migrations", verbosity=0) + call_command("makemigrations", "--check", "migrations", stdout=out) + self.assertEqual("No changes detected in app 'migrations'\n", out.getvalue()) def test_makemigrations_migration_path_output(self): """ -- cgit v1.3