Opened 3 years ago

Closed 3 years ago

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

Change History (3)

comment:1 Changed 3 years ago by timo

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

comment:2 Changed 3 years 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 3 years 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.

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