Skip to content

Fix __tracebackhide__ not respected in ExceptionGroup sub-exception tracebacks - #14649

Merged
RonnyPfannschmidt merged 2 commits into
pytest-dev:mainfrom
EternalRights:fix-exceptiongroup-tracebackhide
Aug 25, 2026
Merged

Fix __tracebackhide__ not respected in ExceptionGroup sub-exception tracebacks#14649
RonnyPfannschmidt merged 2 commits into
pytest-dev:mainfrom
EternalRights:fix-exceptiongroup-tracebackhide

Conversation

@EternalRights

Copy link
Copy Markdown
Contributor

ExceptionGroup tracebacks use the native style, which calls
traceback.format_exception with the group's traceback. The top-level
traceback gets filtered for __tracebackhide__, but format_exception then
walks each sub-exception's original __traceback__ and renders those frames
unfiltered, so __tracebackhide__ set inside a sub-exception's call stack has
no effect.

Fix by building a traceback.TracebackException and filtering its stack in
place, recursing into sub-exceptions and __cause__/__context__ chains. The
original exception objects are not mutated. Native output style is kept.

Closes #14036

…racebacks

ExceptionGroup tracebacks use the native style via
traceback.format_exception. The top-level traceback gets filtered,
but format_exception then walks each sub-exception's original
__traceback__ and renders those frames unfiltered, so
__tracebackhide__ set inside a sub-exception's call stack has no
effect.

Fix by building a traceback.TracebackException and filtering its
stack in place, recursing into sub-exceptions and __cause__/__context__
chains. Original exception objects are not mutated.

Closes pytest-dev#14036
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 24, 2026
@RonnyPfannschmidt
RonnyPfannschmidt merged commit 75e6815 into pytest-dev:main Aug 25, 2026
36 checks passed
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.

ExceptionGroups do not respect __tracebackhide__

2 participants