Have pytest.raises match against exception __notes__#11227
Have pytest.raises match against exception __notes__#11227nicoddemus merged 12 commits intopytest-dev:mainfrom
__notes__#11227Conversation
nicoddemus
left a comment
There was a problem hiding this comment.
LGTM, left some simple suggestions.
src/_pytest/python_api.py
Outdated
| >>> with pytest.raises(ValueError, match=r'must be \d+$'): | ||
| ... raise ValueError("value must be 42") | ||
|
|
||
| The ``match`` argument searches the formatted exception string, which includes any ``__notes__``: |
There was a problem hiding this comment.
Perhaps it would be nice to add a link to the relevant PEP?
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
for more information, see https://pre-commit.ci
…ytest into match-exception-notes
|
Thanks for the quick review! Addressed comments, finished up, and added a couple more test cases. |
| """ | ||
| __tracebackhide__ = True | ||
| value = str(self.value) | ||
| value = "\n".join( |
There was a problem hiding this comment.
We might want to work with @agronholm to ensure note helpers in the backport as well as shared formatting as follow up
There was a problem hiding this comment.
The tests here don't seem to involve exception groups though.
There was a problem hiding this comment.
@agronholm my impression is that exception notes are closely related and my understanding is that integration with the backport may be helpful as per agronholm/exceptiongroup#31 and since formatting may also be affected my impression is that the most benefit for library users would come from having one integration place instead of multiple
There was a problem hiding this comment.
About formatting: I don't think there is a function in traceback that provides the exact rendering pytest expects. I think all the methods that traceback provides will include the exception type.
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
Im happy now that the design decision is done and we will use match all
- Use pytest.raises(match=...) instead of manual exception capture - Add towncrier changelog entries for both nddata and coordinates - Follows pytest-dev/pytest#11227 recommendation
Closes #11223
Adds support for matching against
__notes__added to an exception withinpytest.raises. See issue for discussion/ design.Notes
add_noteis only available in 3.11+exceptiongroup: Add note helper? agronholm/exceptiongroup#31TODO
AUTHORSin alphabeticalchangelogfolder, with a name like<ISSUE NUMBER>.<TYPE>.rst.