Description
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:
- You put the business code you want to test in a different module (one that is not imported from a template) and register the tags manually via
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.