-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
raisesgroup followups #13279
base: main
Are you sure you want to change the base?
raisesgroup followups #13279
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.
looks good, but needs some merge fixes - consider rebasing?
changelog/13192.feature.2.rst
Outdated
@@ -0,0 +1 @@ | |||
The context-manager form of :func:`pytest.raises` now has a ``check`` parameter that takes a callable that should return `True` when passed the raised exception if it should be accepted. |
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 think we really need to spell out this api, for people who aren't really familiar with Pytest. Something like
You can now pass :func:
with pytest.raises(check=fn): <pytest.raises>
, wherefn
is a function which takes a raised exception and returns a boolean. The test fails if no exception was raised (as usual with :func:pytest.raises
), passes if an exception is raised andfn
returns True, and re-raises the exception iffn
returns False (which also fails the test).
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'm not sure the changelog needs to cater super hard to people not familiar with pytest at all, but agree it should be less technical. Though we no longer just reraise on fail, and made it clearer that it can be used in conjunction with the other parameters.
Hi, I missed the previous episode of this so I hope you don't mind me asking a question late.
|
with pytest.raises(OSError, check=lambda e: e.errno == errno.EINVAL):
...
# versus
with pytest.raises(OSError) as excinfo:
...
assert excinfo.value.errno == errno.EINVAL but for the |
* renames src/_pytest/raises_group.py to src/_pytest/raises.py * moves pytest.raises from src/_pytest/python_api.py to src/_pytest/raises.py * adds several newsfragments that should've been bundlen with * add RaisesGroup & Matcher pytest-dev#13192 * add more detailed error message if you try to do RaisesGroup((ValueError, TypeError)) * mess around with ValueError vs TypeError on invalid expected exception
Followup to #13192, which got increasingly unwieldy towards the end so I'm going to do a couple followup PR's to clean up loose ends
src/_pytest/raises_group.py
tosrc/_pytest/raises.py
pytest.raises
fromsrc/_pytest/python_api.py
tosrc/_pytest/raises.py
RaisesGroup((ValueError, TypeError))
TypeError
or aValueError
, or if it matters at all