Skip to content

Add new ExceptionInfo.group_contains assertion helper method#11424

Merged
Zac-HD merged 4 commits intopytest-dev:mainfrom
lanzz:exceptioninfo-groupcontains
Sep 17, 2023
Merged

Add new ExceptionInfo.group_contains assertion helper method#11424
Zac-HD merged 4 commits intopytest-dev:mainfrom
lanzz:exceptioninfo-groupcontains

Conversation

@lanzz
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

lanzz commented Sep 10, 2023

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

Copy link
Copy Markdown
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?

Comment thread src/_pytest/_code/code.py
Comment thread src/_pytest/_code/code.py Outdated
@lanzz
Copy link
Copy Markdown
Contributor Author

lanzz commented Sep 15, 2023

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

@Zac-HD
Copy link
Copy Markdown
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
Copy Markdown
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.
@lanzz lanzz force-pushed the exceptioninfo-groupcontains branch from c808cae to 5ace48c Compare September 17, 2023 21:28
@lanzz
Copy link
Copy Markdown
Contributor Author

lanzz commented Sep 17, 2023

Also rebased onto main

@Zac-HD
Copy link
Copy Markdown
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
Copy Markdown
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