Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template tags missing when the tags module is imported during test collection #64

Closed
wants to merge 3 commits into from

Conversation

izquierdo
Copy link
Contributor

I'm hitting this error

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:

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.

Can confirm that this fixes #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.

@nedbat
Copy link
Owner

nedbat commented May 25, 2021

Thanks, I've cherry-picked the fix commit as 6622791.

@nedbat nedbat closed this May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests for template tags with pytest-xdist and pytest-cov break view tests using the template tags
2 participants