diff options
| author | Tomáš Ehrlich <tomas.ehrlich@gmail.com> | 2014-11-15 16:03:20 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-03-14 16:08:23 -0400 |
| commit | 8414fcf16b9cfa8d989db913f0961fc4ce18c71b (patch) | |
| tree | f906670ec6f40074371de53cb38cbb6aded2e73d /tests | |
| parent | ae87ad005f7b62f5fa5a29ef07443fa1bbb9baf0 (diff) | |
Fixes #23643 -- Added chained exception details to debug view.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/view_tests/tests/py3_test_debug.py | 42 | ||||
| -rw-r--r-- | tests/view_tests/tests/test_debug.py | 3 |
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/view_tests/tests/py3_test_debug.py b/tests/view_tests/tests/py3_test_debug.py new file mode 100644 index 0000000000..38d840f07a --- /dev/null +++ b/tests/view_tests/tests/py3_test_debug.py @@ -0,0 +1,42 @@ +""" +Since this file contains Python 3 specific syntax, it's named without a test_ +prefix so the test runner won't try to import it. Instead, the test class is +imported in test_debug.py, but only on Python 3. + +This filename is also in setup.cfg flake8 exclude since the Python 2 syntax +error (raise ... from ...) can't be silenced using NOQA. +""" +import sys + +from django.test import RequestFactory, TestCase +from django.views.debug import ExceptionReporter + + +class Py3ExceptionReporterTests(TestCase): + + rf = RequestFactory() + + def test_reporting_of_nested_exceptions(self): + request = self.rf.get('/test_view/') + try: + try: + raise AttributeError('Top level') + except AttributeError as explicit: + try: + raise ValueError('Second exception') from explicit + except ValueError: + raise IndexError('Final exception') + except Exception: + # Custom exception handler, just pass it into ExceptionReporter + exc_type, exc_value, tb = sys.exc_info() + + explicit_exc = 'The above exception ({0}) was the direct cause of the following exception:' + implicit_exc = 'During handling of the above exception ({0}), another exception occurred:' + reporter = ExceptionReporter(request, exc_type, exc_value, tb) + html = reporter.get_traceback_html() + self.assertIn(explicit_exc.format("Top level"), html) + self.assertIn(implicit_exc.format("Second exception"), html) + + text = reporter.get_traceback_text() + self.assertIn(explicit_exc.format("Top level"), text) + self.assertIn(implicit_exc.format("Second exception"), text) diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 51f86f225f..95dfb8f875 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -28,6 +28,9 @@ from ..views import ( sensitive_kwargs_function_caller, sensitive_method_view, sensitive_view, ) +if six.PY3: + from .py3_test_debug import Py3ExceptionReporterTests # NOQA + class CallableSettingWrapperTests(TestCase): """ Unittests for CallableSettingWrapper |
