Avoid IndexError when the pytest traceback cut has a single entry#171
Closed
rachfop wants to merge 1 commit into
Closed
Avoid IndexError when the pytest traceback cut has a single entry#171rachfop wants to merge 1 commit into
rachfop wants to merge 1 commit into
Conversation
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.
a7c9bf8 to
464c65d
Compare
Member
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. |
Member
|
@rachfop - ping? Will close as stale in a week or so... |
Member
|
@adamtheturtle - not sure if you have context on this, but closing as stale for now. |
Contributor
|
No ideas from me. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SybilItem._traceback_filterre-roots the displayed traceback at the framebelow the example frame (
tb[1]) to hide Sybil's own frames. When the exampleframe is the deepest frame in a failure's traceback,
traceback.cut(path=example_module_path)collapses to a single entry, so
tb[1]raisesIndexError.Because this runs inside pytest's failure-reporting path, that
IndexErrorsurfaces as a pytest
INTERNALERRORthat aborts the whole session and hides theexample 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.pythat reproduces thesingle-entry cut and asserts
_traceback_filterno longer raises../happy.shpasses (tests at 100% coverage, ruff, mypy, docs build).