Skip to content

Commit af6afad

Browse files
committed
changing exit code when creating a migration and no changes are required
1 parent 733b37d commit af6afad

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

piccolo/apps/migrations/commands/new.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ async def _create_new_migration(app_config: AppConfig, auto=False) -> None:
7575
)
7676

7777
if sum([len(i.statements) for i in alter_statements]) == 0:
78-
sys.exit("No changes detected - exiting.")
78+
print("No changes detected - exiting.")
79+
sys.exit(0)
7980

8081
file_contents = render_template(
8182
migration_id=_id,

tests/apps/migrations/commands/test_new.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import os
22
import shutil
33
from unittest import TestCase
4+
from unittest.mock import call, patch, MagicMock
45

5-
from piccolo.conf.apps import AppConfig
66
from piccolo.apps.migrations.commands.new import (
77
_create_new_migration,
88
BaseMigrationManager,
99
new,
1010
)
11+
from piccolo.conf.apps import AppConfig
1112
from piccolo.utils.sync import run_sync
1213

1314
from tests.base import postgres_only
@@ -41,13 +42,16 @@ def test_create_new_migration(self):
4142
self.assertTrue(len(migration_modules.keys()) == 1)
4243

4344
@postgres_only
44-
def test_new_command(self):
45+
@patch("piccolo.apps.migrations.commands.new.print")
46+
def test_new_command(self, print_: MagicMock):
4547
"""
4648
Call the command, when no migration changes are needed.
4749
"""
4850
with self.assertRaises(SystemExit) as manager:
4951
run_sync(new(app_name="example_app", auto=True))
5052

51-
self.assertEqual(
52-
manager.exception.__str__(), "No changes detected - exiting."
53+
self.assertEqual(manager.exception.code, 0)
54+
55+
self.assertTrue(
56+
print_.mock_calls[-1] == call("No changes detected - exiting.")
5357
)

0 commit comments

Comments
 (0)