jinja: jinja2 no longer supports the pytest loader
Currently, jinja2 expects either _path defined or get_filenames: https://github.com/pallets/jinja/blob/master/src/jinja2/loaders.py#L262-L281
The pytest assertion rewriter defines neither (see https://github.com/pytest-dev/pytest/blob/master/src/_pytest/assertion/rewrite.py#L48), and as such running a test suite on a source code that has the following global:
from jinja2 import PackageLoader
LOADER = PackageLoader(__name__, "templates")
will fail with:
raise ValueError(
E ValueError: The 'xxx' package was not installed in a way that PackageLoader understands.
Not sure if here jinja2 needs to support more ways to get the template rooot, or pytest loader is missing some methods.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (12 by maintainers)
Just released 2.11.2 that reverts the change. 3.0 will have the new behavior with the fix.
It looks like maybe
importlib_resourcesgot an update that allows subdirectories? https://importlib-resources.readthedocs.io/en/latest/changelog (links).html#v1-1-0 Might be good to check out as well.this might be a helpful starting point, I’ll see if I can shimmy some code into jinja2: https://github.com/asottile/aspy.refactor_imports/blob/519ee18ea75e0045b9b53644c627c6817b2a0748/aspy/refactor_imports/classify.py#L76-L91