Design discussion: how should we test for expected `ExceptionGroup`s?
See original GitHub issuePython 3.11 has been released with the new ExceptionGroup type, and there’s a great backport too.
As people start to write code which can raise ExceptionGroups, there’s also going to be a corresponding need to test that they raised the expected group of exceptions, and that’s where this issue comes in: our existing APIs aren’t particularly helpful for this. For example, in the PR to use ExceptionGroups for Pytest teardown errors, I used with pytest.raises(...) to catch the group, but then had to manually unpack the structure and do isinstance() checks by hand.
I’d like to take our time and find the right API, rather than hurrying to any particular conclusion, and that should be based on a volume and diversity of experience that just doesn’t exist yet. This issue therefore exists to collect use-cases, design ideas, and discussion, until we’re confident that we can ship the right thing for the next decade.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)

Top Related StackOverflow Question
To me that is something that needs a outside of pytest experiment that can iterate breaking
Its hard to get right, I’d like to use something like the ideas from dirty equals for it
I am also looking forward to an official solution. In the meantime FWIW, I have pieced this together: https://gist.github.com/xaviergmail/90355b7611dcff27a6a0a60297666865
(In my case, I’m testing for exceptiongroups thrown by cattrs)