Re: [Django] #34823: assertTemplateUsed() context manager crashes for templates without names. (was: _assert_template_used fails with anonymous templates)

3 views
Skip to first unread message

Django

unread,
Sep 9, 2023, 1:42:09 AM9/9/23
to django-...@googlegroups.com
#34823: assertTemplateUsed() context manager crashes for templates without names.
-----------------------------------+------------------------------------
Reporter: Arian | Owner: Arian
Type: Bug | Status: assigned
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* status: new => assigned
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
* owner: nobody => Arian
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Thanks for the report, I was able to reproduce it with the following test:

{{{!diff
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index cdb0453e44..b0eb0b0f83 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -547,6 +547,12 @@ class
AssertTemplateUsedContextManagerTests(SimpleTestCase):
response = self.client.get("/test_utils/no_template_used/")
self.assertTemplateUsed(response, "template_used/base.html")

+ with self.assertRaisesMessage(
+ AssertionError, "No templates used to render the response"
+ ):
+ with self.assertTemplateUsed("template_used/base.html"):
+ self.client.get("/test_utils/no_template_used/")
+
def test_msg_prefix(self):
msg_prefix = "Prefix"
msg = f"{msg_prefix}: No templates used to render the response"

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34823#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages