-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Style: Use type.__name__ in raises error messages for consistency #13862
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
base: main
Are you sure you want to change the base?
Style: Use type.__name__ in raises error messages for consistency #13862
Conversation
dca856e to
581ceb6
Compare
testing/python/raises.py
Outdated
| with pytest.raises( | ||
| Failed, | ||
| match=r"DID NOT RAISE <class 'raises(\..*)*ClassLooksIterableException'>", | ||
| match=r"DID NOT RAISE 'ClassLooksIterableException'", |
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.
This makes me wonder if we should maybe use __qualname__ and possibly __module__ for non-builtins in the output, what do others think? IMHO it's fine without, as it should be clear from context.
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 do wonder if this has the potentila to break plugin testsuites
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 it's fair to do so. We've had it before that exception messages changed somehow, and often that required changes in pytest's testsuite and AFAIK sometimes elsewhere. Don't think exception messages are part of our API essentially.
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.
This makes me wonder if we should maybe use qualname and possibly module for non-builtins in the output, what do others think
Good question. It is an interesting idea, but I agree with you that it should be clear from context and has the potential of cluttering the output. I suggest we leave like this for now.
241d818 to
a395424
Compare
4838955 to
2072395
Compare
| if len(self.expected_exceptions) == 1: | ||
| fail(f"DID NOT RAISE {self.expected_exceptions[0].__name__}") | ||
| else: | ||
| names = ", ".join(f"{x.__name__}" for x in self.expected_exceptions) |
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.
nitpick: This can be simplified as it's already a string:
| names = ", ".join(f"{x.__name__}" for x in self.expected_exceptions) | |
| names = ", ".join(x.__name__ for x in self.expected_exceptions) |
Purpose
Addresses a
FIXMEintesting/python/raises_group.pythat pointed out the inconsistent use ofrepr(type)vstype.__name__in error messages.This PR refactors the
RaisesContext.__exit__method insrc/_pytest/raises.pyto consistently usetype.__name__(e.g.,'ValueError') instead ofrepr(type)(e.g.,<class 'ValueError'>) in all "DID NOT RAISE" error messages. This improves the readability and consistency of these assertion failures.Tests
Because the library's error message format was changed, this PR also updates all the tests in
testing/python/raises.pyandtesting/python/raises_group.pythat were asserting the old, inconsistent message format.