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.
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 rangeCommon 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.
pytest -p no:cacheprovider -p no:randomly # disable suspects
pytest -p no:<plugin> # narrow it downAlign pytest and plugin versions
Pin pytest and the offending plugin to a compatible, current pair and reinstall cleanly.
pip install --upgrade pytest pytest-<plugin>
pip list | grep -i pytest # confirm versionsHow 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.