|
@@ -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):
|
|
|
"""
|