django.template.exceptions.TemplateSyntaxError: 'l10n' is not a registered tag library.
when trying to load Django's l10n library in a template while using pytest and django_coverage_plugin. Tests pass when the plugin is not used. This started happening after adding from django.templatetags.l10n import localize to a test module.
This happens in Python 3.6 with Django 1.11.
From my investigation of the issue, it's triggered in the following way:
Thus Django considers l10n not to be a template tags module and does not register it and considers the template engine to be fully loaded.
I believe the root issue here is that check_debug() is trying to import template engines too early and that the if not apps.ready: check is not enough. Unfortunately I couldn't find any other way to detect that the engines have been loaded other than by looking at the internal variable _engines.
I'm hitting this error
when trying to load Django's
l10n
library in a template while using pytest and django_coverage_plugin. Tests pass when the plugin is not used. This started happening after addingfrom django.templatetags.l10n import localize
to a test module.This happens in Python 3.6 with Django 1.11.
From my investigation of the issue, it's triggered in the following way:
l10n
template tag'template'
is a prefix of'templatetags'
and this causes check_debug() to be run at a time whendjango.template.engines
hasn't imported the engines yet.l10n
, this import works but the module does not yet have aregister
attributel10n
not to be a template tags module and does not register it and considers the template engine to be fully loaded.I believe the root issue here is that
check_debug()
is trying to import template engines too early and that theif not apps.ready:
check is not enough. Unfortunately I couldn't find any other way to detect that the engines have been loaded other than by looking at the internal variable_engines
.Can confirm that this fixes https://github.com/nedbat/django_coverage_plugin/issues/63 using the test case attached there.
Wasn't able to add a test to this PR as the bug depends on pytest's collector.