-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Improve doc/typing for ExceptionInfo.match
#6776
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
Conversation
I also think the message could be improved: diff --git i/src/_pytest/_code/code.py w/src/_pytest/_code/code.py
index 6f2cd3480..fceb3ac8b 100644
--- i/src/_pytest/_code/code.py
+++ w/src/_pytest/_code/code.py
@@ -643,7 +643,7 @@ def match(self, regexp: "Union[str, Pattern]") -> "Literal[True]":
"""
__tracebackhide__ = True
if not re.search(regexp, str(self.value)):
- assert 0, "Pattern {!r} not found in {!r}".format(regexp, str(self.value))
+ assert 0, "Pattern {!r} does not match {!r}".format(regexp, str(self.value))
return True |
src/_pytest/_code/code.py
Outdated
raised. | ||
Check whether the regular expression `regexp` matches the string | ||
representation of the exception using :func:`python:re.search`. | ||
If it matches `True` is returned (so that it is possible to write |
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.
Is there a reason to do assert excinfo.match()
as opposed to just excinfo.match()
? If not, I would just omit the comment in the parenthesis (or move it to a code comment) so it doesn't sound like an endorsement.
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 also think the message could be improved:
Agreed. There's a choice whether to use "string matches regex" or "regex matches string", depends on perspective I suppose. But what you suggest is definitely more precise than "not found in" which can be interpreted as just an in
check.
No description provided.