Skip to content
Latchkey

pytest "INTERNALERROR ... IndexError" - Crash During the Run

An INTERNALERROR> means pytest itself (or one of its plugins) crashed, not your test. An IndexError deep in pytest/plugin internals usually points at a version mismatch between pytest and a plugin, or a buggy hook.

What this error means

The run aborts with a traceback prefixed INTERNALERROR> ending in IndexError: list index out of range, with frames inside _pytest/... or a plugin package - not your test code. No test results are reported.

pytest output
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File ".../_pytest/main.py", line ..., in wrap_session
INTERNALERROR>   File ".../pytest_some_plugin/plugin.py", line 84, in pytest_collection_modifyitems
INTERNALERROR>     item = items[idx]
INTERNALERROR> IndexError: list index out of range

Common causes

pytest/plugin version mismatch

A plugin built for a different pytest version calls an internal API that changed, crashing inside a hook with an IndexError or similar.

A buggy or incompatible plugin hook

A third-party (or local conftest) hook mishandles the items/collection list, indexing past its end. The crash is in the plugin, surfaced via pytest’s INTERNALERROR.

How to fix it

Bisect by disabling plugins

Find the culprit by running with plugins turned off, then re-enabling.

Terminal
pytest -p no:cacheprovider -p no:randomly   # disable suspects
pytest -p no:<plugin>                        # narrow it down

Align pytest and plugin versions

Pin pytest and the offending plugin to a compatible, current pair and reinstall cleanly.

Terminal
pip install --upgrade pytest pytest-<plugin>
pip list | grep -i pytest   # confirm versions

How to prevent it

  • Pin pytest and its plugins to compatible versions in a lockfile.
  • Upgrade pytest and plugins together, not independently.
  • Reproduce INTERNALERRORs by toggling plugins to isolate the cause.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →