Repository navigation
Filter internal and hidden traceback frames for custom items - #15430
RonnyPfannschmidt wants to merge 4 commits into
Conversation
Node._traceback_filter returned the traceback unchanged, so failures in custom Item subclasses showed the runner, pluggy and plugin wrapper frames as well as frames marked with __tracebackhide__. Apply the same generic filtering Function falls back to: drop pytest/pluggy frames (keeping the original if that empties it), then hidden frames. --full-trace still shows everything. Closes #7692. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014GZsRDDitRunjszt4LxLHz
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014GZsRDDitRunjszt4LxLHz
| def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback: | ||
| return excinfo.traceback | ||
| traceback = excinfo.traceback | ||
| ntraceback = traceback.filter(filter_traceback) |
There was a problem hiding this comment.
Generated with Claude assistance
This removes internal and generated frames everywhere, including below the item's own code. For example:
runtestcalls a pytest helper that raises from inside_pytestwithout__tracebackhide__, orruntestexec()s user code compiled with a<...>filename (the notebook and markdown runner plugins do this).
In both cases the frame that raised is dropped and the traceback ends at the caller. A test function in the same situation keeps that frame, because Function only cuts the frames above the test.
Could we cut the leading internal frames instead? Something like:
def _traceback_filter(self, excinfo):
traceback = excinfo.traceback
for i, entry in enumerate(traceback):
if filter_traceback(entry):
traceback = traceback[i:]
break
return traceback.filter(excinfo)(If nothing matches, this keeps the full traceback, which also covers the fallback case.)
Related: ExceptionInfo._getreprcrash ignores tbfilter. It picks the last frame that isn't __tracebackhide__, even when that frame is in _pytest or is generated code. With this filter, the short summary line, the path:line: Error line and the junitxml message can point at a frame the displayed traceback no longer shows. A cut avoids this, because it never drops the innermost frames.
There was a problem hiding this comment.
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.
Agreed, the filter dropped frames below the item. Done in 657e4aa, along the lines you sketched: TracebackEntry.isinternal()/isgenerated() (with filter_traceback as a thin wrapper) and Traceback.cut_internal(); Function's innermost fallback and the _obj-less / path-less Collector cases now reuse Node._traceback_filter.
One addition: Node._traceback_filter first cuts at the node's own method frame (the first entry whose self is the node, like Function cuts at the test), and only falls back to cut_internal() when there is none (e.g. an error in a conftest hook). The leading cut alone stops at the first third-party frame, so with a plugin pytest_runtest_call wrapper on the stack (hypothesis has one) the skipping.py/runner.py frames below it came back.
Generated by Claude Code
| @pytest.mark.parametrize( | ||
| "failure", ["raise ValueError('custom failure')", "pytest.fail('custom failure')"] | ||
| ) | ||
| def test_custom_item_traceback_filter( |
There was a problem hiding this comment.
Generated with Claude assistance
These tests only check that def from_call( (runner.py) is gone. Could we add:
- a check that pluggy frames (e.g.
_multicall) are gone, - a case where the error is raised in a frame below
runtest(ideally from a<generated>filename) and that frame is still shown, - a run with the default
--tb=auto, since every case here uses--tb=long?
There was a problem hiding this comment.
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.
Added in 657e4aa: the main test now also checks _multicall and runs with both --tb=auto and --tb=long; new tests cover a <gen> frame below runtest (kept), a plugin pytest_runtest_call wrapper (cut), a failing conftest hook (leading cut), plus unit tests for cut_internal() and isgenerated().
Generated by Claude Code
|
Note I used Claude (an AI assistant) to help with this review. I went through the findings myself, but please push back on anything that looks off.
I think a cut would be closer to what Some follow-ups on lines this PR doesn't touch:
A possible shape for the cut, which would also tidy up the existing helpers:
I'd avoid putting this into |
Per review: filtering dropped pytest/pluggy and generated frames below the item too. Add TracebackEntry.isinternal()/isgenerated() and Traceback.cut_internal(). Node._traceback_filter now starts at the node's own method frame (like Function starts at the test function), falling back to cutting the leading internal entries, then applies __tracebackhide__. Function's innermost fallback and path-less Collectors reuse it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014GZsRDDitRunjszt4LxLHz
Requested by Ronny · project thread
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.
Node._traceback_filterwas a no-op, so customItemfailures showed the runner/pluggy/plugin-wrapper frames and__tracebackhide__frames. It now does the generic part of whatFunctiondoes: drop pytest/pluggy frames (falling back to the full traceback if that empties it), then hidden frames;--full-traceis unchanged. The test covers a custom item failing in setup and runtest, withValueErrorandpytest.fail, with and without--full-trace.Closes #7692. Alternative to #15256, which only handles
__tracebackhide__.Generated by Claude Code