question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

See https://github.com/pytest-dev/pytest-cov/issues/285

Here’s a repository that reproduces the behaviour (see README):

https://github.com/TauPan/pytest-django-xdist-cov-bug

(Which also reproduces #36)

General description:

1.) You have a template tag library “foo” 2.) You have a view using a template using that library via load foo 3.) Being a thorough tester, you decide you need a test for the template tag library, which means you have to from app.templatetags import foo in your test. 4.) And of course you need to test the view using the templatetag. 5.) And maybe you have to test the templatetag before the view (not sure if this is relevant) e.g. pytest discovery puts it before the view test. 6.) And since you have many tests, you run pytest --cov -n 2

Which results in an error like the following:

django.template.exceptions.TemplateSyntaxError: ‘foo’ is not a registered tag library.

The error only appears if both -n and --cov are used.

There are two workarounds at this point:

However the django documentation at https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/ (or 1.11 or any version) does not mention that templatetags libraries need to be imported anywhere. I’m not sure if any of the relevant modules mentions that (pytest-cov, pytest-xdist, pytest-django or django_coverage_plugin). Since production code runs without those imports (and --cov and -n2 on their own as well) I suspect there’s still a bug somewhere and importing those modules explicitly is just a workaround, with the advantage that it’s simpler than my initial workaround of moving the busines code of the template tags and filters out of the tag library module and testing it separately.

So my take would be that discovery of template tag libraries should not depend on the presence of --cov and -n.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nedbatcommented, Jun 8, 2021
1reaction
nedbatcommented, May 25, 2021

This is fixed in 6622791.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tests for template tags with pytest-xdist and ... - Bountysource
Tests for template tags with pytest-xdist and pytest-cov break view tests using the template tags.
Read more >
pytest-cov - Read the Docs
This plugin produces coverage reports. Compared to just using coverage run this plugin does some extras: • Subprocess support: you can fork ...
Read more >
pytest-cov - PyPI
This plugin produces coverage reports. Compared to just using coverage run this plugin does some extras: Subprocess support: you can fork or run...
Read more >
Test Custom template tags in Django#6 - YouTube
Django Testing Tutorials- How to test Inclusion Template Tags | Test Custom template tags in Django#6, https://youtu.be/Z7x3Wb2BDs8.
Read more >
Configuration options — Nengo Bones 0.4.2 docs
As an example, in this section we will use the “test” template, ... exe pip install "pytest-xdist>=1.16.0" exe pip install "pytest-cov>=2.6.0" exe pip ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found