Improve handling of traceback elision - #4826
Open
Zac-HD wants to merge 3 commits into
Open
Conversation
`@impersonate` used to overwrite `co_filename` and `co_firstlineno` on the wrappers we generate, so that they claimed to be defined where the user's test is. That hid our internals from pytest and IPython, but at the cost of wrong line numbers - a traceback would quote the `@given(...)` line instead of the line which actually raised, and position exception carets against the wrong source. Instead we leave the code objects alone, and rely on the existing `__hypothesistracebackhide__` marker plus `__tracebackhide__` in the generated wrapper body. Frames which do survive - under `--tb=native`, or outside pytest - name `<hypothesis>` or a real file in our package. `inspect.getsource` on a wrapped test used to work by accident, via the faked location; `_patching` now follows `__wrapped_target` explicitly. `test_healthcheck_traceback_is_hidden` asserted a magic distance between two lines of pytest output, which no longer holds; a snapshot covering this and several other scenarios replaces it in a later commit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UioESJtvAnhpFvdyr4k9du
We already dropped our frames from the start of a traceback, but not from between two frames of user code - so a test which draws from a strategy that raises showed the whole engine in between. The trimmed traceback is now built from fresh entries rather than by reassigning `tb_next`, which would mutate a traceback that other code may still hold a reference to. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UioESJtvAnhpFvdyr4k9du
Covers the scenarios from issue HypothesisWorks#4681 along with health checks, exception groups, errors inside strategies, and an invalid @given signature. Most run under `--tb=native`, which unlike pytest's own rendering shows every frame that survived trimming. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UioESJtvAnhpFvdyr4k9du
Zac-HD
force-pushed
the
claude/hypothesis-pr-review-iiu2yc
branch
from
July 26, 2026 20:17
7e4334a to
b44ba40
Compare
Member
|
Let This is pretty unfortunate and seems likely to have bad downstream effects. A user would have to know about I'm pretty seriously considering alternatives in the shape of "rebuild the column mapping table ourselves"... I have claude going on a possible design in the background but I'm not sure it's going to pan out. |
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 #4681, closes #4696 (essentially an updated copy with merge conflicts fixed).