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)

Commits related to this issue

Most upvoted comments

Just released 2.11.2 that reverts the change. 3.0 will have the new behavior with the fix.

It looks like maybe importlib_resources got 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.