Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24094 closed Bug (fixed)

Unable to run a subset of template tests

Reported by: Tim Graham Owned by: Aymeric Augustin
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

./runtests.py template_tests.syntax_tests

fails with RemovedInDjango20Warning on 9 of the tests complaining that "You haven't defined a TEMPLATES setting".

Change History (8)

comment:1 by Aymeric Augustin, 9 years ago

I can reproduce this.

I understand why these tests fail -- they run isolated from Django settings, and to make sure they don't accidentally use a globally configured DjangoTemplates engine, TEMPLATES is set to None for these tests.

What I fail to understand is why they pass when not run in isolation e.g. ./runtests.py template_tests. Perhaps I missed some cases when handling the setting_changed signal.

comment:2 by Aymeric Augustin, 9 years ago

Owner: changed from nobody to Aymeric Augustin
Status: newassigned

comment:3 by Preston Timmons, 9 years ago

I took a look at this. I didn't find the exact issue, but I noticed a few things:

  1. The tests that fail all have "{% load custom %}".
  1. The tags that cause the problem are inclusion tags that have a "get_template" call in the decorator. Removing these removes the warnings.
  1. I think there is a side-effect when template_tests.test_loaders is imported by unittest discovery.

The tests pass with this command:

./runtests.py template_tests.test_loaders template_tests.syntax_tests

But fail in reverse:

./runtests.py template_tests.test_loaders template_tests.syntax_tests --reverse

comment:4 by Preston Timmons, 9 years ago

More specifically, a side-effect seems to appear in template_tests.test_loaders.DeprecatedRenderToStringTest.test_no_empty_dict_push_to_stack. The syntax_tests fail when run in combination with test_loaders if that method is removed.

comment:5 by Preston Timmons, 9 years ago

I added a pull request for this. It fixes the problem by moving inclusion tags from template_tests.templatetags.custom into their own module, template_tests.templatetags.inclusion.

The warnings were masked before because template_tests.test_loaders.DeprecatedRenderToStringTest.test_no_empty_dict_pushed_to_stack uses a template that runs {% load custom %}. Since the get_template calls are evaluated at import time, no warning was raised when template_tests.syntax_tests later loaded that file.

Since the syntax_tests don't use the inclusion tags, the tests now run isolated from any global settings.

comment:6 by Preston Timmons, 9 years ago

Has patch: set

comment:7 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 665e0aa6ec80a48492033a3b2b4ffdfaae3c78eb:

Fixed #24094 -- Enabled template tests to run individually.

comment:8 by Aymeric Augustin, 9 years ago

Smart. Thanks a lot Preston.

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