Fix __tracebackhide__ handling for ExceptionGroup tracebacks - #15094
Closed
Dextheking1 wants to merge 1 commit into
Closed
Dextheking1 wants to merge 1 commit into
Dextheking1 wants to merge 1 commit into
Conversation
Match filtered frames by identity instead of (filename, lineno) in _filter_tracebackexception: distinct traceback entries can share the same source location while having different __tracebackhide__ values (e.g. via recursion), in which case a hidden frame was incorrectly retained when a visible frame from the same location was kept. Fixes pytest-dev#14940.
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.
Fixes #14940.
_filter_tracebackexceptionmatched kept frames by(filename, lineno). That key identifies a source location, not an individual traceback occurrence: when two frames share the same location but have different__tracebackhide__values (e.g. recursion), a hidden frame was retained because a visible frame from the same location was kept.The fix matches frames by identity instead:
TracebackException.stackholds oneFrameSummaryper raw traceback frame in the same (outermost-first) order, so both are walked in parallel and aFrameSummaryis kept only when its own raw traceback entry survived filtering. This also makes custom callabletbfilters behave per-occurrence.Reproducer from the issue (recursion with
__tracebackhide__ = number == 1inside anExceptionGroup): before, the recursive call line appeared twice in the native traceback; after, it appears once.Added a regression test (
test_tracebackhide_in_exceptiongroup_shared_source_locationintesting/code/test_excinfo.py) plus a towncrier entry.testing/code/test_excinfo.py(190 passed),testing/test_terminal.py+testing/test_runner.py(287 passed) all green locally.