-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix ExceptionGroup
traceback filtering of pytest internals
#13380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ExceptionGroup
traceback filtering of pytest internals
#13380
Conversation
Test failed with results such as this previously, the exception groups tracebacks show lots of pytest internal frames that are filtered from other exceptions.
|
ExceptionGroup
traceback filteringExceptionGroup
traceback filtering of pytest internals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome to see a new pytest contributor! And very happy you're improving my dirty hack for exceptiongroups :)
A note when submitting PR's is to avoid extraneous changes that muddles the diff and makes it harder to see what's actually being changed. The rename of the traceback
variable to traceback_
, as well as moving the call in _truncate_recursive_traceback
to its own method, both qualifies as that.
If you really do think those changes makes the code non-trivially better, they should be in their own commit, so reviewers can view the diff of other commits separately.
This PR is really just ~3-4 lines changed, but it looks much bigger.
Shadowing the traceback
module isn't great for sure, so I'm probably in favor of keeping that change.
Adding _repr_exception_group_traceback
I'm against. Ideally ReprTraceback
should just support exceptiongroups so in the long term the method shouldn't be needed.
Have you checked that we always only need to filter the top If you don't come up with any reasonable scenario where it'd happen I'd just pop a comment noting that we don't filter any sub-exceptions since they shouldn't have any internal frames. |
b808c67
to
0ee759c
Compare
* Import functions from `traceback` directly, to allow free use of `traceback` as a variable name. * Extract `_filtered_traceback` into a function. * Inline `_repr_exception_group_traceback` given it is used only in one place. * Make a type alias for the type of `tbfilter`.
0ee759c
to
3c580a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @gesslerpd!
I took the liberty of cleaning up the code a bit (the rationale is in the commit message), otherwise looks great to me.
That's a good point... however I cannot think of a scenario right now where that could happen... 🤔 |
The test is parametrized and only fails in 3 cases (6 total because of the backport tests) when the |
@nicoddemus The docs are failing on the typehint refactor not sure best way to fix that (edit: I took it out of the TYPE_CHECKING conditional so docs build can see it, nvm that was a bad idea I now repeated the hint directly just for the doc referencing part of code not optimal but it works)
|
Thanks for taking a look, here's the original error for reference:
However using the type directly kind defeats the purpose of the alias -- I will attempt to find a workaround later, otherwise I guess we will need to drop the type alias. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good! Still an ugly hack, but slightly less ugly~ ✨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Edited the test to fail on
main
branch and was able to fix rather than submitting an issue. See sample output of failing test in comment below for reference.This fix preserves the existing fallback logic for exception groups #9159 and adds traceback filtering only.