Opened 13 years ago
Closed 13 years ago
#17086 closed Bug (fixed)
humanize and markup tests modify global templatetags library state
Reported by: | Carl Meyer | Owned by: | nobody |
---|---|---|---|
Component: | contrib.humanize | Version: | dev |
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 |
Description
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 manage.py 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.
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).