Skip to content

INTERNALERROR when generating html report using pytest-cov 7.1.0 with jinja #748

Description

@cdleonard

It seems that latest version of pytest-cov will attempt to parse jinja2 files as python sources and fail. Error looks like this:

============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.1.1, pluggy-1.6.0
rootdir: /home/leonard/Projects/check-pytest-cov-jinja
configfile: pyproject.toml
plugins: cov-7.1.0
collected 1 item

test_jinja.py .
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/_pytest/main.py", line 330, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>                          ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/_pytest/main.py", line 384, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR>     raise exception
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/_pytest/logging.py", line 816, in pytest_runtestloop
INTERNALERROR>     return (yield)  # Run all the tests.
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/_pytest/terminal.py", line 708, in pytest_runtestloop
INTERNALERROR>     result = yield
INTERNALERROR>              ^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 152, in _multicall
INTERNALERROR>     teardown.send(result)
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pytest_cov/plugin.py", line 362, in pytest_runtestloop
INTERNALERROR>     self.cov_total = self.cov_controller.summary(self.cov_report)
INTERNALERROR>                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pytest_cov/engine.py", line 44, in ensure_topdir_wrapper
INTERNALERROR>     return meth(self, *args, **kwargs)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/pytest_cov/engine.py", line 189, in summary
INTERNALERROR>     self.cov.html_report(ignore_errors=True, directory=output)
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/coverage/control.py", line 1275, in html_report
INTERNALERROR>     return reporter.report(morfs)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/coverage/html.py", line 392, in report
INTERNALERROR>     self.write_html_page(ftr)
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/coverage/html.py", line 481, in write_html_page
INTERNALERROR>     file_data = self.datagen.data_for_file(ftr.fr, ftr.analysis)
INTERNALERROR>                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/coverage/html.py", line 152, in data_for_file
INTERNALERROR>     for lineno, tokens in enumerate(fr.source_token_lines(), start=1):
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/coverage/phystokens.py", line 136, in source_token_lines
INTERNALERROR>     soft_key_lines = find_soft_key_lines(source)
INTERNALERROR>                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/leonard/Projects/check-pytest-cov-jinja/.venv/lib/python3.12/site-packages/coverage/phystokens.py", line 97, in find_soft_key_lines
INTERNALERROR>     for node in ast.walk(ast.parse(source)):
INTERNALERROR>                          ^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.12/ast.py", line 52, in parse
INTERNALERROR>     return compile(source, filename, mode, flags,
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "<unknown>", line 2
INTERNALERROR>     {% for key in arg %}
INTERNALERROR>      ^
INTERNALERROR> SyntaxError: invalid syntax

============================== 1 passed in 0.06s ===============================

This does not happen with pytest-cov 7.0.0

Minimal project reproducing just this issue: https://github.com/cdleonard/check-pytest-cov-jinja

To reproduce the failure: uv run pytest --cov --cov-report=html
To check it works using 7.0.0: uv run --with pytest-cov==7.0.0 pytest --cov --cov-report=html

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