#20918 closed Cleanup/optimization (fixed)

Tidy up implementation of custom assertions

Reported by: mjtamlyn Owned by: nobody
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The custom assertions provided by Django have a significant amount of duplication between the true and false cases - e.g. between assertContains and assertNotContains. There appear to be subtle difference and it concerns me that perhaps some of these are bugfixes which have only been applied to one of the methods.

For example, assertNotContains seems to not handle streaming responses.

Attachments (0)

Change History (3)

comment:1 Changed 11 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 11 months ago by ersran9

I've written an initial patch . I'm not really sure if this is the way to go forward. If it is, then I'll move forward with other functions that has the same problem.

comment:3 Changed 10 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In a2374bcf476b49441793f1ad213126b07543da54:

Fixed #20918 -- Tidied up implementation of custom assertions

  1. Moved common logic between assertContains and assertNotContains into a separate function _assert_contains()
  1. Moved common logic between assertTemplateUsed and assertTemplateNotUsed into a separate function _assert_templateused()

Thanks Marc Tamlyn for the report and review.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.