Skip to content

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

Merged
merged 8 commits into from
Feb 21, 2020

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Feb 20, 2020

No description provided.

@blueyed
Copy link
Contributor Author

blueyed commented Feb 20, 2020

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

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
Copy link
Member

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.

Copy link
Member

@bluetech bluetech left a 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.

@blueyed blueyed merged commit 2be06ba into pytest-dev:master Feb 21, 2020
@blueyed blueyed deleted the excinfo-match branch February 21, 2020 15:41
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.

3 participants