mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Fixed #20445 -- Raised original exception after command error
This commit is contained in:
parent
4280217f31
commit
888c86dcf3
2 changed files with 19 additions and 17 deletions
|
@ -1305,13 +1305,15 @@ class CommandTypes(AdminScriptTestCase):
|
|||
sys.stderr = err = StringIO()
|
||||
try:
|
||||
command.execute = lambda args: args # This will trigger TypeError
|
||||
with self.assertRaises(SystemExit):
|
||||
command.run_from_argv(['', ''])
|
||||
err_message = err.getvalue()
|
||||
# Exceptions other than CommandError automatically output the traceback
|
||||
self.assertIn("Traceback", err_message)
|
||||
self.assertIn("TypeError", err_message)
|
||||
|
||||
# If the Exception is not CommandError it should always
|
||||
# raise the original exception.
|
||||
with self.assertRaises(TypeError):
|
||||
command.run_from_argv(['', ''])
|
||||
|
||||
# If the Exception is CommandError and --traceback is not present
|
||||
# this command should raise a SystemExit and don't print any
|
||||
# traceback to the stderr.
|
||||
command.execute = raise_command_error
|
||||
err.truncate(0)
|
||||
with self.assertRaises(SystemExit):
|
||||
|
@ -1320,12 +1322,12 @@ class CommandTypes(AdminScriptTestCase):
|
|||
self.assertNotIn("Traceback", err_message)
|
||||
self.assertIn("CommandError", err_message)
|
||||
|
||||
# If the Exception is CommandError and --traceback is present
|
||||
# this command should raise the original CommandError as if it
|
||||
# were not a CommandError.
|
||||
err.truncate(0)
|
||||
with self.assertRaises(SystemExit):
|
||||
with self.assertRaises(CommandError):
|
||||
command.run_from_argv(['', '', '--traceback'])
|
||||
err_message = err.getvalue()
|
||||
self.assertIn("Traceback (most recent call last)", err_message)
|
||||
self.assertIn("CommandError", err_message)
|
||||
finally:
|
||||
sys.stderr = old_stderr
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue