-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Demonstrating how bad the wrapped message is, they should be the same #57
Conversation
Hey @txomon, thanks for the feedback! Those wrappers were introduced in #36, perhaps @asfaltboy and others could chime in? I see your example showcases a pretty bad message because the mocks were called with only keyword arguments but expected to be called with positional arguments but I agree it could be improved. I will take a closer look tomorrow, right now I have to go to bed. 😁 |
* assert both args and kwargs at the same time for a more detailed report * update tests to assert the above This improves on PR pytest-dev#36 according to the points raised in PR pytest-dev#57
Hi guys, I clearly see the output is intolerable, it's totally my fault for not following through with the improvement suggestion I raised in original PR #36 . However, I wrote a quick fix in commit 86e03ea, that visibly appends the "pytest introspected" message to the end of the original mock error message so that both "simple" and detailed errors are visible. The new branch I reference above also contains a few fixes for tests and tox.ini (since we now need to import mock in our tests). @txomon if you can, please try the descriptive-mock-assert-wrap branch and let us know if it works for you. |
I won't be able to test it in the next days (will be on vacations without I have seen the code and is there any reason to create the AssetionError in Cheers! On Wed, 3 Aug 2016 18:30 Pavel Savchenko, notifications@github.com wrote:
|
@txomon do you mean why don't we change this raise statement from
to
? Honestly I don't know why not, it's legacy from #27 I think |
Yes, that way the message is either maintained or improved On Wed, 3 Aug 2016 20:08 Pavel Savchenko, notifications@github.com wrote:
|
Hey @asfaltboy, thanks a lot for joining the discussion so quickly, and already volunteering to work on it to boot! 😄 About your patch, I think that's the right direction although I'm not a big fan of printing the message like you did, I would rather we add to the original message and raise a new __tracebackhide__ = True
try:
__wrapped_mock_method__(*args, **kwargs)
except AssertionError as e:
__mock_self = args[0]
if __mock_self.call_args is not None:
actual_args, actual_kwargs = __mock_self.call_args
try:
assert (args[1:], kwargs) == (actual_args, actual_kwargs)
except AssertionError as detailed_comparison:
msg = (str(e) + "\n\n... pytest introspection follows:\n" +
str(detailed_comparison))
raise AssertionError(msg)
raise This way we have all the information in the same place, instead of capturing stdout and displaying it in a separate section of the error report. |
This is a bit over my head, I mean I'm not sure what the differences / trade-offs are of the above mentioned approaches of re-raising the error, beyond coding style that is. In any case, I'm happy to comply with any requests and will submit a PR if everyone's happy with the code in the branch. EDIT: @nicoddemus I just noticed I left in a |
@asfaltboy Basically, reraising an exception is cheaper because the object is already there, and most of all, you don't need to know how that exception is built or extra arguments it might need. Finally, composing strings by addition is not recommended
Notice that those |
@asfaltboy I did
instead of |
Thanks @Chronial this seems to fix the failing |
Discussion continued in #58 |
This test demonstrates how bad those assert wraps in the library can be.
Is totally misleading and displays incomplete information.
The output of the test so that you understand the big difference:
As you can see, the actual message (marked with
+
in the diff) doesn't speak at all about the keyword arguments, and although the diff may be more verbose all the content there is terrible.This needs to improve by either making:
IMO the assert wrapper function should just disappear, but up to you.
EDIT: Instead of creating the exception again, I would really raise the existing one within the assert wrapper
EDIT2: I think it would also be nice to know why the assert wrapper is necessary at all...
EDIT3: Just in case, tests fail on purpose.