Skip to content

Avoid IndexError when the pytest traceback cut has a single entry#171

Closed
rachfop wants to merge 1 commit into
simplistix:mainfrom
rachfop:fix-pytest-traceback-single-entry
Closed

Avoid IndexError when the pytest traceback cut has a single entry#171
rachfop wants to merge 1 commit into
simplistix:mainfrom
rachfop:fix-pytest-traceback-single-entry

Conversation

@rachfop

@rachfop rachfop commented Jun 16, 2026

Copy link
Copy Markdown

SybilItem._traceback_filter re-roots the displayed traceback at the frame
below the example frame (tb[1]) to hide Sybil's own frames. When the example
frame is the deepest frame in a failure's traceback, traceback.cut(path=example_module_path)
collapses to a single entry, so tb[1] raises IndexError.

Because this runs inside pytest's failure-reporting path, that IndexError
surfaces as a pytest INTERNALERROR that aborts the whole session and hides the
example that actually failed, instead of reporting it.

I hit this with a library whose examples execute through a deferred realization
step: the failure's traceback had the Sybil example frame as its deepest frame,
collapsing the cut to one entry.

The fix guards the lookup — when the cut has more than one entry the re-rooting
is unchanged; when it has a single entry the cut traceback is kept as-is, so the
failure is reported normally.

Includes a regression test in tests/test_functional.py that reproduces the
single-entry cut and asserts _traceback_filter no longer raises. ./happy.sh
passes (tests at 100% coverage, ruff, mypy, docs build).

SybilItem._traceback_filter re-roots the displayed traceback at the frame
below the example frame (tb[1]). When the example frame is the deepest in
the traceback -- for example a failure surfaced from deferred or
asynchronous evaluation -- the cut traceback is a single entry, so tb[1]
raises IndexError from inside pytest failure reporting. That aborts the run
with an INTERNALERROR and hides the actual failure.

Guard the lookup so a single-entry cut keeps the cut traceback instead.
@rachfop rachfop force-pushed the fix-pytest-traceback-single-entry branch from a7c9bf8 to 464c65d Compare June 16, 2026 18:03
@cjw296

cjw296 commented Jun 17, 2026

Copy link
Copy Markdown
Member

I hit this with a library whose examples execute through a deferred realization
step: the failure's traceback had the Sybil example frame as its deepest frame,
collapsing the cut to one entry.

Why is this framework truncating the stack frames of the traceback? The test you've added does this is an artificial way, but I'd like to understand what's happening in the real code.

@cjw296

cjw296 commented Jun 23, 2026

Copy link
Copy Markdown
Member

@rachfop - ping? Will close as stale in a week or so...

@cjw296

cjw296 commented Jul 4, 2026

Copy link
Copy Markdown
Member

@adamtheturtle - not sure if you have context on this, but closing as stale for now.

@cjw296 cjw296 closed this Jul 4, 2026
@adamtheturtle

Copy link
Copy Markdown
Contributor

No ideas from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants