Skip to content

Add new ExceptionInfo.group_contains assertion helper method #11424

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

Merged
merged 4 commits into from
Sep 17, 2023

Conversation

lanzz
Copy link
Contributor

@lanzz lanzz commented Sep 10, 2023

Tests if a captured exception group contains an expected exception. Will raise AssertionError if the wrapped exception is not an exception group. Supports recursive search into nested exception groups.

(edit by Zac) Fixes #10441.

@lanzz
Copy link
Contributor Author

lanzz commented Sep 10, 2023

Curious, these failures don't seem to have anything to do with my changes 🤔

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great Mihail - thanks so much!

I've added some design comments below which I think will let us close the linked issue; your implementation and tests already look great so we should be able to merge pretty soon. I'm also unsure what's happening with those failing tests, but rebasing on main might help?

@lanzz
Copy link
Contributor Author

lanzz commented Sep 15, 2023

@Zac-HD I've updated the PR with the suggested changes.

@Zac-HD
Copy link
Member

Zac-HD commented Sep 17, 2023

I think it'd be nice to add a usage example to the reference docs for pytest.raises() and maybe also the tutorial, but I'm happy for that to come in a follow-up PR.

@lanzz
Copy link
Contributor Author

lanzz commented Sep 17, 2023

Updated docs as well 👍

lanzz and others added 4 commits September 17, 2023 22:28
Tests if a captured exception group contains an expected exception.
Will raise `AssertionError` if the wrapped exception is not an exception group.
Supports recursive search into nested exception groups.
…bout the `match` keyword parameter)
@lanzz lanzz force-pushed the exceptioninfo-groupcontains branch from c808cae to 5ace48c Compare September 17, 2023 21:28
@lanzz
Copy link
Contributor Author

lanzz commented Sep 17, 2023

Also rebased onto main

@Zac-HD
Copy link
Member

Zac-HD commented Sep 17, 2023

Beautiful! Thanks so much @lanzz, I'm going to really enjoy using this 🤩

@Zac-HD Zac-HD merged commit 8b7f94f into pytest-dev:main Sep 17, 2023
@nicoddemus
Copy link
Member

@Zac-HD when merging, prefer to squash the commits when they do not bring much value if they land separately into main:

image

IMHO those commits would be better squashed together as a single commit. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Design discussion: how should we test for expected ExceptionGroups?
3 participants