diff --git a/tests/template_backends/test_utils.py b/tests/template_backends/test_utils.py index c3eb6577a0..d1f3aaa793 100644 --- a/tests/template_backends/test_utils.py +++ b/tests/template_backends/test_utils.py @@ -3,20 +3,17 @@ from django.template import engines from django.test import SimpleTestCase, override_settings -class TemplateStringsTests(SimpleTestCase): +class TemplateUtilsTests(SimpleTestCase): - @override_settings(TEMPLATES=[{ - 'BACKEND': 'raise.import.error', - }]) + @override_settings(TEMPLATES=[{'BACKEND': 'raise.import.error'}]) def test_backend_import_error(self): """ - Failing to import a backend keeps raising the original import error. - - Regression test for #24265. + Failing to import a backend keeps raising the original import error + (#24265). """ - with self.assertRaises(ImportError): + with self.assertRaisesRegex(ImportError, "No module named '?raise"): engines.all() - with self.assertRaises(ImportError): + with self.assertRaisesRegex(ImportError, "No module named '?raise"): engines.all() @override_settings(TEMPLATES=[{ @@ -27,13 +24,13 @@ class TemplateStringsTests(SimpleTestCase): }]) def test_backend_improperly_configured(self): """ - Failing to initialize a backend keeps raising the original exception. - - Regression test for #24265. + Failing to initialize a backend keeps raising the original exception + (#24265). """ - with self.assertRaises(ImproperlyConfigured): + msg = 'app_dirs must not be set when loaders is defined.' + with self.assertRaisesMessage(ImproperlyConfigured, msg): engines.all() - with self.assertRaises(ImproperlyConfigured): + with self.assertRaisesMessage(ImproperlyConfigured, msg): engines.all() @override_settings(TEMPLATES=[{ @@ -42,5 +39,9 @@ class TemplateStringsTests(SimpleTestCase): 'BACKEND': 'django.template.backends.django.DjangoTemplates', }]) def test_backend_names_must_be_unique(self): - with self.assertRaises(ImproperlyConfigured): + msg = ( + "Template engine aliases aren't unique, duplicates: django. Set " + "a unique NAME for each engine in settings.TEMPLATES." + ) + with self.assertRaisesMessage(ImproperlyConfigured, msg): engines.all()