Skip to content

Fix __tracebackhide__ for ExceptionGroup frames sharing a source location - #14941

Open
Amine-LG wants to merge 1 commit into
pytest-dev:mainfrom
Amine-LG:fix-exceptiongroup-tracebackhide-recursion
Open

Fix __tracebackhide__ for ExceptionGroup frames sharing a source location#14941
Amine-LG wants to merge 1 commit into
pytest-dev:mainfrom
Amine-LG:fix-exceptiongroup-tracebackhide-recursion

Conversation

@Amine-LG

Copy link
Copy Markdown

Fixes #14940.

_filter_tracebackexception() matched filtered traceback entries to Python's formatted frames using (filename, line number). Separate traceback entries can share those values while having different __tracebackhide__ values, causing a hidden frame to remain visible.

This change identifies each occurrence by the identity of its underlying raw traceback entry instead. Pytest's TracebackEntry and Python's FrameSummary sequences preserve traceback order, so they are walked together and only occurrences that survived filtering are kept.

The pairing is non-strict because sys.tracebacklimit can shorten Python's formatted traceback. A separate test protects that behavior.

This is a follow-up to the ExceptionGroup traceback filtering added in #14649.

Tests

  • Added a regression test for visible and hidden recursive calls from the same line.
  • Added a regression test for a shortened traceback when sys.tracebacklimit is set.
  • python -m pytest -q testing/code
  • pre-commit run --files AUTHORS changelog/14940.bugfix.rst src/_pytest/_code/code.py testing/code/test_excinfo.py

AI assistance

I used AI tools during the investigation and implementation. I manually reproduced the issue and reviewed and tested the final changes.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 26, 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

1 participant