Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#17604 closed New feature (fixed)

Make use of assertTemplateUsed and assertTemplateNotUsed as ContextManagers

Reported by: gregmuellegger Owned by: gregmuellegger
Component: Testing framework Version: 1.3
Severity: Normal Keywords: assertTemplateUsed, assertTemplateNotUsed, contextmanager
Cc: kmike84@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It can be useful to use the assertTemplateUsed assertion on a limited block of code via a context manager instead on a request:

with self.assertTemplateUsed('template_used/base.html'):

This is something that already proofed useful in the soc2011/form-rendering branch. It's implemented there and is well tested:

Same is true for assertTemplateNotUsed.

Attachments (2)

17604-assertTemplateUsed.1.diff (12.9 KB) - added by gregmuellegger 5 years ago.
17604-assertTemplateUsed.2.diff (13.0 KB) - added by gregmuellegger 5 years ago.
merged with trunk

Download all attachments as: .zip

Change History (10)

comment:1 Changed 5 years ago by gregmuellegger

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

The feature is implemented here:
The compare view:

Would be good if anyone could in particular review the docs, since my english is not the best at the moment.

Changed 5 years ago by gregmuellegger

comment:2 Changed 5 years ago by gregmuellegger

  • Has patch set

comment:3 Changed 5 years ago by kmike

  • Cc kmike84@… added

comment:4 Changed 5 years ago by julien

  • Triage Stage changed from Unreviewed to Accepted

Changed 5 years ago by gregmuellegger

merged with trunk

comment:5 Changed 5 years ago by carljm

  • Patch needs improvement set

I'm seeing three errors and one failure in the tests with the latest patch:

comment:6 Changed 5 years ago by gregmuellegger

  • Patch needs improvement unset

Did you applied the patch with "patch -p1 < t17604-assertTemplateUsed.2.diff"? I tried so and had the same problem, since it doesn't create the two empty files:


Use git apply t17604-assertTemplateUsed.2.diff instead or create those empty files by hand.
Sorry, I don't know how to make the patch work otherwise :-(

comment:7 Changed 5 years ago by carljm

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

In [17412]:

Fixed #17604 - Added context-manager capability to assertTemplateUsed and assertTemplateNotUsed. Thanks Greg Müllegger.

comment:8 Changed 5 years ago by carljm

Oops, my bad :-) Thanks for the pointer on getting the patch applied properly.

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