summaryrefslogtreecommitdiff
path: root/tests/admin_scripts
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-03-09 12:38:45 +0100
committerClaude Paroz <claude@2xlibre.net>2013-03-09 12:38:45 +0100
commit6a91b638423de954b7d96c38e2372100800139fb (patch)
tree379a5241795106bd3bc1dc0711e799396b2d71de /tests/admin_scripts
parent5e80571bf92d93c177bea9e5ee7d89153ecadbad (diff)
Fixed #19923 -- Display tracebacks for non-CommandError exceptions
By default, show tracebacks for management command errors when the exception is not a CommandError. Thanks Jacob Radford for the report.
Diffstat (limited to 'tests/admin_scripts')
-rw-r--r--tests/admin_scripts/tests.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 42595982d9..90f77206cd 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -16,7 +16,7 @@ import codecs
from django import conf, bin, get_version
from django.conf import settings
-from django.core.management import BaseCommand
+from django.core.management import BaseCommand, CommandError
from django.db import connection
from django.test.simple import DjangoTestSuiteRunner
from django.utils import unittest
@@ -1297,22 +1297,34 @@ class CommandTypes(AdminScriptTestCase):
Also test proper traceback display.
"""
command = BaseCommand()
- command.execute = lambda args: args # This will trigger TypeError
+ def raise_command_error(*args, **kwargs):
+ raise CommandError("Custom error")
old_stderr = sys.stderr
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()
- self.assertNotIn("Traceback", err_message)
+ # Exceptions other than CommandError automatically output the traceback
+ self.assertIn("Traceback", err_message)
self.assertIn("TypeError", err_message)
+ command.execute = raise_command_error
+ err.truncate(0)
+ with self.assertRaises(SystemExit):
+ command.run_from_argv(['', ''])
+ err_message = err.getvalue()
+ self.assertNotIn("Traceback", err_message)
+ self.assertIn("CommandError", err_message)
+
+ err.truncate(0)
with self.assertRaises(SystemExit):
command.run_from_argv(['', '', '--traceback'])
err_message = err.getvalue()
self.assertIn("Traceback (most recent call last)", err_message)
- self.assertIn("TypeError", err_message)
+ self.assertIn("CommandError", err_message)
finally:
sys.stderr = old_stderr