Opened 4 years ago

Closed 4 years ago

#17086 closed Bug (fixed)

humanize and markup tests modify global templatetags library state

Reported by: carljm Owned by: nobody
Component: contrib.humanize 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 tests for both contrib.humanize and contrib.markitup use add_to_builtins to (permanently) add their respective template tag libraries to the context of all rendered templates. This is done at module-level in their test modules, and there is no attempt to clean up or isolate the effect of this change.

This can cause templates rendered in unrelated user tests to behave differently depending on whether they are run alone or as part of a suite including the markup/humanize tests. For instance, if a template fails to {% load markup %} or {% load humanize %} when it should, and a test renders that template, that test would succeed under a full test but fail if run without the contrib/humanize tests.

This also affects Django's own test suite.

I think the proper solution here is to (a) use the appropriate {% load %} tags in the test templates for those test suites, and (b) temporarily monkeypatch django.template.base.templatetags_modules so that it includes the templatetag module for humanize during humanize's tests, and likewise for markup.

If #17085 is fixed, it would provide an alternative way to fix this without needing the monkeypatch.

Change History (2)

comment:1 Changed 4 years ago by carljm

Part (b) here was pure fail, there's no monkeypatching needed; if the contrib/humanize tests are running, that means contrib/humanize is installed and the template tags are available. So this is a simple fix (just stop using add_to_builtins and use {% load %} instead).

comment:2 Changed 4 years ago by carljm

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

In [17031]:

Fixed #17086 -- Removed pollution of global template-builtins from markup and humanize tests.

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