A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pytest-dev/pytest-cov/issues/285 below:

Tests for template tags with pytest-xdist and pytest-cov break view tests using the template tags · Issue #285 · pytest-dev/pytest-cov · GitHub

This was a weird one for me to figure out, but it should be simple to reproduce:

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.

(maybe related to #110, but I don't see any of the problems described in that issue)

Workaround:

from django import template
from ._foo import (tag1, tag2)

register = template.Library()

register.filter(is_safe=True)(tag1)
register.tag()(tag2)

And of course you import _foo in your test, instead of the template library.

I'm not sure if I should file this with pytest-xdist or pytest-cov, since it definitely only occurs if both are used. I'm filing this here first and we can figure out if it really is xdist's fault.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4