diff --git a/tests/view_tests/templates/debug/template_error.html b/tests/view_tests/templates/debug/template_error.html new file mode 100644 index 0000000000..16d8ce6700 --- /dev/null +++ b/tests/view_tests/templates/debug/template_error.html @@ -0,0 +1,2 @@ +Template with error: +{% cycle %} diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 9b0feab8ea..828d59a88f 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -5,11 +5,13 @@ import re import sys import tempfile from io import StringIO +from pathlib import Path from django.conf.urls import url from django.core import mail from django.core.files.uploadedfile import SimpleUploadedFile from django.db import DatabaseError, connection +from django.shortcuts import render from django.template import TemplateDoesNotExist from django.test import RequestFactory, SimpleTestCase, override_settings from django.test.utils import LoggingCaptureMixin, patch_logger @@ -605,6 +607,26 @@ class PlainTextReportTests(SimpleTestCase): reporter = ExceptionReporter(request, None, "I'm a little teapot", None) reporter.get_traceback_text() + @override_settings(DEBUG=True) + def test_template_exception(self): + request = self.rf.get('/test_view/') + try: + render(request, 'debug/template_error.html') + except Exception: + exc_type, exc_value, tb = sys.exc_info() + reporter = ExceptionReporter(request, exc_type, exc_value, tb) + text = reporter.get_traceback_text() + templ_path = Path(Path(__file__).parent.parent, 'templates', 'debug', 'template_error.html') + self.assertIn( + 'Template error:\n' + 'In template %(path)s, error at line 2\n' + ' \'cycle\' tag requires at least two arguments\n' + ' 1 : Template with error:\n' + ' 2 : {%% cycle %%} \n' + ' 3 : ' % {'path': templ_path}, + text + ) + def test_request_with_items_key(self): """ An exception report can be generated for requests with 'items' in