Exception raised in a command should raise CommandError with call_command, but SystemExit when run from command line
(self)
| 87 | management.call_command(("explode",)) |
| 88 | |
| 89 | def test_system_exit(self): |
| 90 | """Exception raised in a command should raise CommandError with |
| 91 | call_command, but SystemExit when run from command line |
| 92 | """ |
| 93 | with self.assertRaises(CommandError) as cm: |
| 94 | management.call_command("dance", example="raise") |
| 95 | self.assertEqual(cm.exception.returncode, 3) |
| 96 | dance.Command.requires_system_checks = [] |
| 97 | try: |
| 98 | with captured_stderr() as stderr, self.assertRaises(SystemExit) as cm: |
| 99 | management.ManagementUtility( |
| 100 | ["manage.py", "dance", "--example=raise"] |
| 101 | ).execute() |
| 102 | self.assertEqual(cm.exception.code, 3) |
| 103 | finally: |
| 104 | dance.Command.requires_system_checks = "__all__" |
| 105 | self.assertIn("CommandError", stderr.getvalue()) |
| 106 | |
| 107 | def test_no_translations_deactivate_translations(self): |
| 108 | """ |
nothing calls this directly
no test coverage detected