diff options
| author | Adam Johnson <me@adamj.eu> | 2020-04-14 08:56:16 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-14 13:22:47 +0200 |
| commit | 8e8c3f964e23e669fc563a74750e51abba4c2e3a (patch) | |
| tree | 35a0060e2aebb7f97cc7eff303c2e8c812999787 /tests/user_commands | |
| parent | 6cad911674dc067ffab44eea4f5c8170fa0a89b1 (diff) | |
Refs #29501 -- Allowed customizing exit status for management commands.
Diffstat (limited to 'tests/user_commands')
| -rw-r--r-- | tests/user_commands/management/commands/dance.py | 2 | ||||
| -rw-r--r-- | tests/user_commands/tests.py | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/tests/user_commands/management/commands/dance.py b/tests/user_commands/management/commands/dance.py index 81d6ec9c26..82cfc3338a 100644 --- a/tests/user_commands/management/commands/dance.py +++ b/tests/user_commands/management/commands/dance.py @@ -15,7 +15,7 @@ class Command(BaseCommand): def handle(self, *args, **options): example = options["example"] if example == "raise": - raise CommandError() + raise CommandError(returncode=3) if options['verbosity'] > 0: self.stdout.write("I don't feel like dancing %s." % options["style"]) self.stdout.write(','.join(options)) diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index b770e8e459..b1d00f278d 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -57,12 +57,14 @@ class CommandTests(SimpleTestCase): """ Exception raised in a command should raise CommandError with call_command, but SystemExit when run from command line """ - with self.assertRaises(CommandError): + with self.assertRaises(CommandError) as cm: management.call_command('dance', example="raise") + self.assertEqual(cm.exception.returncode, 3) dance.Command.requires_system_checks = False try: - with captured_stderr() as stderr, self.assertRaises(SystemExit): + with captured_stderr() as stderr, self.assertRaises(SystemExit) as cm: management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute() + self.assertEqual(cm.exception.code, 3) finally: dance.Command.requires_system_checks = True self.assertIn("CommandError", stderr.getvalue()) |
