Skip to content

IndexError if all post-cut traceback frames are hidden #13734

Closed

Description

@cjwatson

Following #13380, pytest-trio's tests fail with an IndexError when trying to display a traceback. Minimal reproducer with pytest 8.4.2 and pytest-trio 0.8.0 on Debian testing:

import pytest

@pytest.mark.trio
async def test_xfail():
    pytest.xfail()
pip list
Package          Version
---------------- -----------
attrs            25.3.0
idna             3.10
iniconfig        2.1.0
outcome          1.3.0.post0
packaging        25.0
pip              25.2
pluggy           1.6.0
Pygments         2.19.2
pytest           8.4.2
pytest-trio      0.8.0
sniffio          1.3.1
sortedcontainers 2.4.0
trio             0.31.0
pytest output
============================================================================= test session starts ==============================================================================
platform linux -- Python 3.13.7, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/cjwatson
plugins: trio-0.8.0
collected 1 item

x.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/main.py", line 289, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>                          ~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/main.py", line 343, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_hooks.py", line 512, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR>     raise exception
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>     ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/logging.py", line 801, in pytest_runtestloop
INTERNALERROR>     return (yield)  # Run all the tests.
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>     ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/terminal.py", line 688, in pytest_runtestloop
INTERNALERROR>     result = yield
INTERNALERROR>              ^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 121, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/main.py", line 367, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_hooks.py", line 512, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR>     raise exception
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>     ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/warnings.py", line 90, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>     ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/assertion/__init__.py", line 192, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>     ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/unittest.py", line 475, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>     ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/faulthandler.py", line 88, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>             ^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 121, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/runner.py", line 117, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>     ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/runner.py", line 136, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>                    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/runner.py", line 248, in call_and_report
INTERNALERROR>     report: TestReport = ihook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_hooks.py", line 512, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR>     raise exception
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>     ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/tmpdir.py", line 308, in pytest_runtest_makereport
INTERNALERROR>     rep = yield
INTERNALERROR>           ^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 139, in _multicall
INTERNALERROR>     teardown.throw(exception)
INTERNALERROR>     ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/skipping.py", line 275, in pytest_runtest_makereport
INTERNALERROR>     rep = yield
INTERNALERROR>           ^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/pluggy/_callers.py", line 121, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/runner.py", line 368, in pytest_runtest_makereport
INTERNALERROR>     return TestReport.from_item_and_call(item, call)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/reports.py", line 377, in from_item_and_call
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/python.py", line 1713, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/nodes.py", line 456, in _repr_failure_py
INTERNALERROR>     return excinfo.getrepr(
INTERNALERROR>            ~~~~~~~~~~~~~~~^
INTERNALERROR>         funcargs=True,
INTERNALERROR>         ^^^^^^^^^^^^^^
INTERNALERROR>     ...<5 lines>...
INTERNALERROR>         truncate_args=truncate_args,
INTERNALERROR>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>     )
INTERNALERROR>     ^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/_code/code.py", line 766, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>            ~~~~~~~~~~~~~~~~^^^^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/_code/code.py", line 1198, in repr_excinfo
INTERNALERROR>     traceback[0]._rawentry,
INTERNALERROR>     ~~~~~~~~~^^^
INTERNALERROR>   File "/home/cjwatson/pytest-env/lib/python3.13/site-packages/_pytest/_code/code.py", line 422, in __getitem__
INTERNALERROR>     return super().__getitem__(key)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~^^^^^
INTERNALERROR> IndexError: list index out of range

I filed this as python-trio/pytest-trio#151 suggesting a fix there, but one of the pytest-trio maintainers said I should file an issue here and made a couple of suggestions. This is getting out of my league - could you have a look and see where this should best be fixed? Thanks!

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Activity

  1. added
    type: bugproblem that needs to be addressed
    topic: tracebacksrelated to displaying and handling of tracebacks
    on Nov 3, 2025
  2. jakkdl commented on Nov 9, 2025

    @jakkdl
    Member

    So the problem arises in

    traceback = filter_excinfo_traceback(self.tbfilter, excinfo)
    reprtraceback = ReprTracebackNative(
    format_exception(
    type(excinfo.value),
    excinfo.value,
    traceback[0]._rawentry,
    )
    )

    when filter_excinfo_traceback returns an empty traceback - which in this case happens because pytest-trio is liberal with using __tracebackhide__ = True. I'm not entirely sure if that's a bug in pytest-trio, but pytest should handle this gracefully. It appears when I wrote that chunk I should've looked closer at some of the logic from earlier in the file and either done something like

    def repr_traceback(self, excinfo: ExceptionInfo[BaseException]) -> ReprTraceback:
    traceback = filter_excinfo_traceback(self.tbfilter, excinfo)
    if isinstance(excinfo.value, RecursionError):
    traceback, extraline = self._truncate_recursive_traceback(traceback)
    else:
    extraline = None
    if not traceback:
    if extraline is None:
    extraline = "All traceback entries are hidden. Pass `--full-trace` to see hidden and internal frames."
    entries = [self.repr_traceback_entry(None, excinfo)]
    return ReprTraceback(entries, extraline, style=self.style)

    or

    if style == "native":
    return ReprExceptionInfo(
    reprtraceback=ReprTracebackNative(
    format_exception(
    self.type,
    self.value,
    self.traceback[0]._rawentry if self.traceback else None,
    )
    ),
    reprcrash=self._getreprcrash(),
    )

    it appears that ReprTracebackNative does have support for extraline - so perhaps the logic in getrepr should be updated as well to also output a line about all traceback entries being hidden.
    EDIT: filtering is disabled in getrepr, so it's not relevant.

  3. jakkdl commented on Dec 2, 2025

    @jakkdl
    Member

    minimal repro:

    def test_things():
        __tracebackhide__ = True
        raise ExceptionGroup("", [ValueError()])
  4. added a commit that references this issue on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: tracebacksrelated to displaying and handling of tracebackstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions