-
Notifications
You must be signed in to change notification settings - Fork 584
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
first draft of handling marker exceptions wrapped in exceptiongroup #4110
base: master
Are you sure you want to change the base?
Conversation
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.
Very nice, thanks! 👍
I think most of the build errors will go away with some of the minor commented changes, the remaining will hopefully be manageable :-)
if sys.version_info < (3, 11): | ||
from exceptiongroup import ExceptionGroup |
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.
if sys.version_info < (3, 11): | |
from exceptiongroup import ExceptionGroup | |
from hypothesis.internal.compat import BaseExceptionGroup |
# multiple frozen exceptions | ||
# TODO: raise a group? The first one? None of them? | ||
raise frozen_exceptions[0] from excgroup | ||
|
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.
Yep, the semantics here (generally) are a good question.
I'd opine:
- If all exceptions are
Frozen
, raise the first (as above). - Else, if exactly one exception is non-
Frozen
,raise
that one [*]. - Otherwise, reconstruct and raise a group with just the non-frozen ones (maybe
.with_traceback(eg.__traceback__)
).
[*] hm, I see, that would cause an undesired unwrapping if user code raises a single-exception ExceptionGroup
. Maybe the second step should be "if exactly one ... and that exception is a StopException
or HypothesisException
.
def test_single_exc_group(data): | ||
raise ExceptionGroup("important message for user", [ValueError()]) | ||
|
||
with RaisesGroup(ValueError, match="important message for user"): |
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.
I'd just catch BaseExceptionGroup
(via hypothesis.internal.compat.BaseExceptionGroup
) and check the subexceptions explicitly, to avoid the trio
dependency.
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.
ye that's probably the way to go. I'm incredibly biased on the matter as the person who wrote trio.testing.RaisesGroup
and is trying to get it added to pytest 😇
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.
(and as a dual maintainer of Pytest and Trio, among other things, I'm pretty keen to support that when I have time 😅)
It should be possible to provoke most of these situations by playing around with multiple tasks failing in different ways. But I think it's fine to create the non-obvious situations explicitly, too. |
Sorry: "most" should probably be replaced by "some" 😁 |
Oh, and one other tip: hypothesis will transform/trim the tracebacks by default, which may be confusing sometimes when working on exceptions and not seeing what you'd expect. See |
I have barely used Hypothesis, and never worked with the codebase, so there are several gaps in code coverage and question marks on implementation decisions. If somebody more familiar wants to take a quick pass and opine it'd be very helpful :)
I can get code coverage by manually raising the specific
ExceptionGroup
s that'll trigger the different branches, but it'd likely be better to do the actual things that causes those exceptions. So would likewise appreciate quick pointers on how to, if at all possible, cause e.g. multipleStopTest
, multipleFrozen
, a singleFrozen
, etc.fixes #4106