Skip to content

Regression: package was not installed in a way that PackageLoader understands. #1148

@jaraco

Description

@jaraco

Expected Behavior

PackageLoader should continue to load from a namespace package even under pytest.

Actual Behavior

Starting with jinja2 2.11, the tests for pmxbot have started failing. They fail when pytest attempts to rewrite the modules for running under test and in doing so, cause the jinja2.loaders.PackageLoader not to recognize the 'pmxbot.web' package. Note that pmxbot is a setuptools namespace package.

Full Traceback

pmxbot/web/__main__.py:1: in <module>
    import pmxbot.web.viewer
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
.tox/python/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:143: in exec_module
    exec(co, module.__dict__)
pmxbot/web/viewer.py:24: in <module>
    jenv = jinja2.Environment(loader=jinja2.loaders.PackageLoader('pmxbot.web'))
.tox/python/lib/python3.8/site-packages/jinja2/loaders.py:288: in __init__
    raise ValueError(
E   ValueError: The 'pmxbot.web' package was not installed in a way that PackageLoader understands.

The error is not triggered when simply importing the package naturally; it only seems to happen during the pytest rewrite.

Your Environment

  • Python version: 3.8.1
  • Jinja version: 2.11.x

Downgrading to Jinja 2.10.3 works around the failure. I suspect #970 is implicated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions