Skip to content

Fix __tracebackhide__ handling for ExceptionGroup tracebacks - #15094

Closed
Dextheking1 wants to merge 1 commit into
pytest-dev:mainfrom
Dextheking1:fix/14940-tracebackhide-exceptiongroup
Closed

Dextheking1 wants to merge 1 commit into
pytest-dev:mainfrom
Dextheking1:fix/14940-tracebackhide-exceptiongroup

Conversation

@Dextheking1

Copy link
Copy Markdown

Fixes #14940.

_filter_tracebackexception matched 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.stack holds one FrameSummary per raw traceback frame in the same (outermost-first) order, so both are walked in parallel and a FrameSummary is kept only when its own raw traceback entry survived filtering. This also makes custom callable tbfilters behave per-occurrence.

Reproducer from the issue (recursion with __tracebackhide__ = number == 1 inside an ExceptionGroup): 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_location in testing/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.

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.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

__tracebackhide__ can retain hidden frames sharing a source location in ExceptionGroup tracebacks

2 participants