#34658 closed New feature (fixed)

New assertion `assertNotInHTML`, like `assertContains` has `assertNotContains`

Reported by: Thibaud Colas Owned by: Nicolas Lupien
Component: Testing framework Version:
Severity: Normal Keywords: testcases, unit tests, HTML, assertions, testing
Cc: Lemuel Sta Ana, Nicolas Lupien Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 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.

Change History (11)

comment:1 by Natalia Bidart, 18 months ago

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!

comment:2 by Mariusz Felisiak, 18 months ago

Resolution: wontfix
Status: newclosed

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 follow the guidelines with regards to requesting features.

comment:3 by Thibaud Colas, 18 months ago

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.

comment:4 by Mariusz Felisiak, 18 months ago

Resolution: wontfix
Status: closednew
Triage Stage: UnreviewedAccepted

Accepting based on the discussion.

Thibaud, would you like to prepare a patch?

comment:5 by Thibaud Colas, 18 months ago

Owner: changed from nobody to Thibaud Colas
Status: newassigned

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

comment:6 by Lemuel Sta Ana, 15 months ago

Cc: Lemuel Sta Ana added

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

comment:7 by Mariusz Felisiak, 13 months ago

Owner: changed from Thibaud Colas to Eva Nanyonga

comment:8 by Nicolas Lupien, 12 months ago

Cc: Nicolas Lupien added
Has patch: set

comment:9 by Mariusz Felisiak, 12 months ago

Needs documentation: set
Owner: changed from Eva Nanyonga to Nicolas Lupien
Patch needs improvement: set

comment:10 by Mariusz Felisiak, 12 months ago

Needs documentation: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 12 months ago

Resolution: fixed
Status: assignedclosed

In 2bf46c38:

Fixed #34658 -- Added SimpleTestCase.assertNotInHTML().

Note: See TracTickets for help on using tickets.
Back to Top