[Django] #34658: New assertion `assertNotInHTML`, like `assertContains` has `assertNotContains`

33 views
Skip to first unread message

Django

unread,
Jun 16, 2023, 9:44:55 AM6/16/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud | Owner: nobody
Colas |
Type: New | Status: new
feature |
Component: Testing | Version:
framework | Keywords: testcases, unit
Severity: Normal | tests, HTML, assertions, testing
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django’s test assertions have `assertContains` and `assertNotContains`
which are HTML-aware ways to check what’s inside a response, similar to
Python’s `assertIn` and `assertNotIn`. Django also offers `assertInHTML` –
but there is no `assertNotInHTML`.

This is very straightforward to implement – and I suspect more than a few
projects will already have their own implementation if they need this, but
I think it’d make much more sense to have this out of the box considering
other "<needle> in <haystack>" assertions have their `-not` equivalent
built in. For me, the main source of pain here is that I use this often
enough to use this but rarely enough to frequently forget:

- Whether this is a Django built-in or not. So I look at
[https://docs.djangoproject.com/en/4.2/topics/testing/tools/#assertions
assertions docs] and am surprised not to see it.
- Whether the project I work on has it or not. So again I have to look
around and potentially add it.

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

Django

unread,
Jun 16, 2023, 12:37:35 PM6/16/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version:
Severity: Normal | Resolution:
Keywords: testcases, unit | Triage Stage:
tests, HTML, assertions, testing | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Natalia Bidart):

I fully agree with the rationale, but for this, perhaps, Thibaud could you
please create a forum post to allow for people to present any counter
argument we may not be considering?

Thanks!

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

Django

unread,
Jun 16, 2023, 12:43:21 PM6/16/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: nobody
Type: New feature | Status: closed
Component: Testing framework | Version:
Severity: Normal | Resolution: wontfix

Keywords: testcases, unit | Triage Stage:
tests, HTML, assertions, testing | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix


Comment:

I'm skeptic. Personally, I find the use of `*NotIn*` assertions really
rare and not the best practice. There can many many reasons why something
is not in something else, and it becomes even more unreliable when we do
this in HTML. It's much more stable and bulletproof to use `*In*`
assertions. I don't think it's worth adding.

Please first start a discussion on the DevelopersMailingList, where you'll
reach a wider audience and see what other think, and
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features follow the guidelines with regards to
requesting features].

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

Django

unread,
Jun 19, 2023, 4:43:50 AM6/19/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: nobody
Type: New feature | Status: closed
Component: Testing framework | Version:
Severity: Normal | Resolution: wontfix
Keywords: testcases, unit | Triage Stage:
tests, HTML, assertions, testing | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Thibaud Colas):

Sorry about that, I thought I had read the ticket creation guidelines to
check what the protocol is, but clearly missed the most important bits.

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

Django

unread,
Jun 20, 2023, 1:48:17 AM6/20/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: nobody
Type: New feature | Status: new

Component: Testing framework | Version:
Severity: Normal | Resolution:
Keywords: testcases, unit | Triage Stage: Accepted
tests, HTML, assertions, testing |

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

* status: closed => new
* resolution: wontfix =>
* stage: Unreviewed => Accepted


Comment:

Accepting based on the [https://forum.djangoproject.com/t/feature-request-
new-assertion-assertnotinhtml-like-assertcontains-has-
assertnotcontains/21711 discussion].

Thibaud, would you like to prepare a patch?

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

Django

unread,
Jun 20, 2023, 8:32:30 PM6/20/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: Thibaud
| Colas
Type: New feature | Status: assigned

Component: Testing framework | Version:
Severity: Normal | Resolution:
Keywords: testcases, unit | Triage Stage: Accepted
tests, HTML, assertions, testing |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Thibaud Colas):

* owner: nobody => Thibaud Colas
* status: new => assigned


Comment:

Yes please! Omg I might eventually become a code contributor.

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

Django

unread,
Sep 26, 2023, 1:23:44 AM9/26/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: Thibaud
| Colas
Type: New feature | Status: assigned
Component: Testing framework | Version:
Severity: Normal | Resolution:
Keywords: testcases, unit | Triage Stage: Accepted
tests, HTML, assertions, testing |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Lemuel Sta Ana):

* cc: Lemuel Sta Ana (added)


Comment:

Adding myself as CC, I'm very interested to see how the patch for this
will be implemented. Hope you don't mind Thibaud.

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

Django

unread,
Nov 24, 2023, 3:35:02 PM11/24/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner:
| evananyonga

Type: New feature | Status: assigned
Component: Testing framework | Version:
Severity: Normal | Resolution:
Keywords: testcases, unit | Triage Stage: Accepted
tests, HTML, assertions, testing |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: Thibaud Colas => evananyonga


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

Django

unread,
Dec 20, 2023, 11:56:38 AM12/20/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: Eva
| Nanyonga

Type: New feature | Status: assigned
Component: Testing framework | Version:
Severity: Normal | Resolution:
Keywords: testcases, unit | Triage Stage: Accepted
tests, HTML, assertions, testing |
Has patch: 1 | Needs documentation: 0

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

* cc: Nicolas Lupien (added)
* has_patch: 0 => 1


Comment:

PR https://github.com/django/django/pull/17626

--
Ticket URL: <https://code.djangoproject.com/ticket/34658#comment:8>

Django

unread,
Dec 21, 2023, 7:35:06 AM12/21/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: Nicolas
| Lupien

Type: New feature | Status: assigned
Component: Testing framework | Version:
Severity: Normal | Resolution:
Keywords: testcases, unit | Triage Stage: Accepted
tests, HTML, assertions, testing |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: Eva Nanyonga => Nicolas Lupien
* needs_better_patch: 0 => 1
* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34658#comment:9>

Django

unread,
Dec 22, 2023, 1:45:08 AM12/22/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: Nicolas
| Lupien
Type: New feature | Status: assigned
Component: Testing framework | Version:
Severity: Normal | Resolution:
Keywords: testcases, unit | Triage Stage: Ready for
tests, HTML, assertions, testing | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/34658#comment:10>

Django

unread,
Dec 22, 2023, 3:36:49 AM12/22/23
to django-...@googlegroups.com
#34658: New assertion `assertNotInHTML`, like `assertContains` has
`assertNotContains`
-------------------------------------+-------------------------------------
Reporter: Thibaud Colas | Owner: Nicolas
| Lupien
Type: New feature | Status: closed
Component: Testing framework | Version:
Severity: Normal | Resolution: fixed

Keywords: testcases, unit | Triage Stage: Ready for
tests, HTML, assertions, testing | 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:"2bf46c3825ad4ec170324791d6f3a329316ae2d4" 2bf46c38]:
{{{
#!CommitTicketReference repository=""
revision="2bf46c3825ad4ec170324791d6f3a329316ae2d4"
Fixed #34658 -- Added SimpleTestCase.assertNotInHTML().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34658#comment:11>

Reply all
Reply to author
Forward
0 new messages