-
-
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
Show detailed py.test assert introspect for call arguments #36
Show detailed py.test assert introspect for call arguments #36
Conversation
Hey @asfaltboy thanks for the PR! I didn't have time yet to try it out in detail, I will do it until the end of the week |
Hey @asfaltboy sorry for not replying earlier. I like the idea in general, although I'm not sure I like the proposed UI. Perhaps we could just provide similar functions in the def test_assert_called_args_with_introspection(mocker):
stub = mocker.stub()
mocker.assert_called_with(stub, *args, **kwargs)
# or perhaps
assert mocker.called_with(stub, *args, **kwargs) What do you think? |
The usage UI is basically unchanged; which is the whole idea of this patch. Instead of manually dissecting arguments and calling, for example, I'm sorry if my code is unclear, the context manager is used ONLY in own tests to test that the raised If you prefer, we can probably as easily move the P.S: I was about to write this as a plugin for myself, but then I found your project and thought it fitting very much with the purpose of |
Oh of course, sorry about that... you are right, I misunderstood the patch. I agree that it would be nice to have this in |
Sure, I can probably do some work during this weekend. Current tests already call all of the With regards to docs, I'm thinking to add a paragraph in (or under) the "improved reporting" section. By the way, do you feel we should add an option to toggle off "advanced introspection"? Something like: [pytest]
mock_argument_introspection_monkeypatch = false |
Oh you are right.
Sounds good.
Sounds good too. 😁 Thanks a lot for taking the time to work on this, I really appreciate it. |
8441253
to
ed8f274
Compare
Sorry for the delay @nicoddemus. I've rebased over the current master and added docs. Unfortunately adding a toggle proved to be difficult to do cleanly and I keep running out of free time. |
I've just tried this, but am also seeing #44 with this (two tracebacks). However, the behavior changes: while you see the whole lists by default, you need to use |
@blueyed you are right of course, the behavior is different from original About #44, I'll leave a comment there. |
Maybe |
Just merged this, will deal with #44 in a separate PR. 😁 Thanks again @asfaltboy! 😄 |
* 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
Why do this
I really enjoy pytest's assertion introspection support, and find it invaluable when it comes to comparing large pieces of data. However, when asserting mock calls with large arguments, I found myself copy-pasting objects into
deepdiff
just to more easily see the difference.Implementation
This may not be a complete solution, but it's the simplest I could think of to start discussing the point.
Among other improvements, we could also check
--assert
mode option, use a custom assertion comparison andraise_from
original mock assertion.Please let me know what you think about this feature?