[Django] #33400: assertTemplateUsed as context manager does not respect count parameter

62 views
Skip to first unread message

Django

unread,
Dec 30, 2021, 8:11:52 AM12/30/21
to django-...@googlegroups.com
#33400: assertTemplateUsed as context manager does not respect count parameter
---------------------------------------------+------------------------
Reporter: karyon | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
See
[https://github.com/django/django/blob/cb383753c0e0eb52306e1024d32a782549c27e61/django/test/testcases.py#L659
the code of assertTemplateUsed]: if it's used as a context manager, the
count parameter is entirely unused. The
[https://docs.djangoproject.com/en/4.0/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
documentation on assertTemplateUsed] does not mention that.

The context manager capability was added in
[https://github.com/django/django/commit/a678e9ea65 a678e9ea65] 10 years
ago. The count parameter was added in
[https://github.com/django/django/commit/17c18844561431aabed89c3bd48de951db7d13ab
#diff-7833da5b45a68d00834388d97dd5c4413e3796497c7bc5e0cc2621b08a2d0df1R543
17c188445] 8 years ago.

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

Django

unread,
Dec 30, 2021, 8:39:22 AM12/30/21
to django-...@googlegroups.com
#33400: assertTemplateUsed()/assertTemplateNotUsed() used as context managers
ignore count and msg_prefix parameters.
-----------------------------------+------------------------------------

Reporter: karyon | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* stage: Unreviewed => Accepted


Comment:

Thanks for the report. Only `template_name` is used in
[https://docs.djangoproject.com/en/stable/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
documented] calls, however it sounds reasonable to honor `msg_prefix` and
`count` when these methods are used as context managers.

Would you like to provide a patch?

--
Ticket URL: <https://code.djangoproject.com/ticket/33400#comment:1>

Django

unread,
Dec 31, 2021, 11:31:45 AM12/31/21
to django-...@googlegroups.com
#33400: assertTemplateUsed()/assertTemplateNotUsed() used as context managers
ignore count and msg_prefix parameters.
-----------------------------------+------------------------------------
Reporter: karyon | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by karyon):

* cc: karyon (added)


Comment:

I could add a note to the documentation, but I don't have the capacity for
properly making this work, sorry.

--
Ticket URL: <https://code.djangoproject.com/ticket/33400#comment:2>

Django

unread,
Dec 31, 2021, 11:21:59 PM12/31/21
to django-...@googlegroups.com
#33400: assertTemplateUsed()/assertTemplateNotUsed() used as context managers
ignore count and msg_prefix parameters.
-------------------------------------+-------------------------------------
Reporter: karyon | Owner: Ad
| Timmering
Type: Bug | Status: assigned

Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ad Timmering):

* owner: nobody => Ad Timmering
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33400#comment:3>

Django

unread,
Jan 1, 2022, 1:34:27 AM1/1/22
to django-...@googlegroups.com
#33400: assertTemplateUsed()/assertTemplateNotUsed() used as context managers
ignore count and msg_prefix parameters.
-------------------------------------+-------------------------------------
Reporter: karyon | Owner: Ad
| Timmering
Type: Bug | Status: assigned
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ad Timmering):

* has_patch: 0 => 1


Comment:

Gave it a shot in [https://github.com/django/django/pull/15267 PR], in the
process aligning error messages to be for context manager use and direct
call use. Comments welcome and appreciated.

--
Ticket URL: <https://code.djangoproject.com/ticket/33400#comment:4>

Django

unread,
Jan 5, 2022, 6:56:17 AM1/5/22
to django-...@googlegroups.com
#33400: assertTemplateUsed()/assertTemplateNotUsed() used as context managers
ignore count and msg_prefix parameters.
-------------------------------------+-------------------------------------
Reporter: karyon | Owner: Ad
| Timmering
Type: Bug | Status: assigned
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33400#comment:5>

Django

unread,
Jan 5, 2022, 10:14:11 AM1/5/22
to django-...@googlegroups.com
#33400: assertTemplateUsed()/assertTemplateNotUsed() used as context managers
ignore count and msg_prefix parameters.
-------------------------------------+-------------------------------------
Reporter: karyon | Owner: Ad
| Timmering
Type: Bug | Status: assigned
Component: Testing framework | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"e700a3714fe668157e5f84ddabfd32d6aac08079" e700a37]:
{{{
#!CommitTicketReference repository=""
revision="e700a3714fe668157e5f84ddabfd32d6aac08079"
Refs #33400 -- Renamed SimpleTestCase._assert_template_used() to
_get_template_used().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33400#comment:6>

Django

unread,
Jan 5, 2022, 10:14:12 AM1/5/22
to django-...@googlegroups.com
#33400: assertTemplateUsed()/assertTemplateNotUsed() used as context managers
ignore count and msg_prefix parameters.
-------------------------------------+-------------------------------------
Reporter: karyon | Owner: Ad
| Timmering
Type: Bug | Status: closed

Component: Testing framework | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"806efe912b846c1fde250c9321d8334b7517cd56" 806efe91]:
{{{
#!CommitTicketReference repository=""
revision="806efe912b846c1fde250c9321d8334b7517cd56"
Fixed #33400 -- Added support for msg_prefix and count arguments to
assertTemplateUsed()/assertTemplateNotUsed() used as context managers.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33400#comment:7>

Reply all
Reply to author
Forward
0 new messages