bpo-35047: Better error messages in unittest.mock#10090
bpo-35047: Better error messages in unittest.mock#10090vstinner merged 6 commits intopython:masterfrom
Conversation
|
@eamanu here is a PR for the issue I filed. |
When developing unit tests with `unittest.mock`, it is common to see error messages like this:
AssertionError: Expected 'info' to not have been called. Called 3 times.
This commit adds the actual list of calls to the error message.
|
@PetterS look the travis error |
|
The Travis error is that an extra string is printed in the documentation. That string only appears here: https://github.com/python/cpython/blame/e42b705188271da108de42b55d9344642170aa2b/Doc/library/weakref.rst#L493 |
|
@vstinner, you seem to have been involved in several PRs involving |
vstinner
left a comment
There was a problem hiding this comment.
What about other methods like assert_called_once_with()?
If you use safe_repr(), please modify other exceptions including mock_calls, like assert_has_calls().
cc @mariocj89
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Notice some examples in |
|
@pablogsal This PR modified |
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
- Rename helper function. Add optional argument. - Use re.compile. - Change NEWS entry.
|
Thanks for the review! All valid points. I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
|
@mariocj89: Would you mind to double check the PR, please? |
| @@ -0,0 +1,3 @@ | |||
| ``unittest.mock`` now includes mock calls in exception messages if | |||
There was a problem hiding this comment.
Nitpick: the change affects also assert_called_once_with and assert_has_calls
There was a problem hiding this comment.
assert_has_calls was only refactored. Is it OK to write assert_called_once(_with)?
There was a problem hiding this comment.
Good point!
About assert_called_once_with, I'd just list the three
mariocj89
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the patience going through the review :)
I concur :-) But the final change is much better than the first version, so it was worth it ;-) If some people complain that the truncated "Calls: ..." is too short, maybe we can discuss the length later. But right now, let's see how users like safe_repr() default length ;-) |
|
Thanks everyone! I am very pleased with the process of contributing to CPython. 👍 |
When developing unit tests with
unittest.mock, it is common to see error messages like this:This commit adds the actual list of calls to the error message.
https://bugs.python.org/issue35047