Visitar URL original
bpo-21269: Provide args and kwargs attributes on mock call objects by kakshay21 · Pull Request #11807 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260111232605/https://github.com/python/cpython/pull/11807
Skip to content

Conversation

@kakshay21
Copy link
Contributor

@kakshay21 kakshay21 commented Feb 10, 2019 •

This PR tries to add this functionality

➜  cpython git:(fix-issue-21269) ✗ ./python.exe
Python 3.8.0a0 (heads/fix-issue-21269-dirty:2433a2ab70, Feb 10 2019, 14:24:54)
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from unittest.mock import Mock
>>> m = Mock()
>>> m(1, a=23)
<Mock name='mock()' id='4552188368'>
>>> m.call_args
call(1, a=23)
>>> m.call_args.args     #after this patch
(1,)
>>> m.call_args.kwargs   #after this patch
{'a': 23}
>>> m.call_args_list[0].args    #after this patch
(1,)
>>> m.call_args_list[0].kwargs   #after this patch
{'a': 23}

https://bugs.python.org/issue21269

@remilapeyre
Copy link

Hi @kakshay21, this patch looks fine but you will need to add a test and add both attributes to call documentation.

@kakshay21
Copy link
Contributor Author

@remilapeyre I've added tests and some documentation. Let me know if I've to add more.

Copy link

@remilapeyre remilapeyre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kakshay21
Copy link
Contributor Author

@remilapeyre any update on this?

@remilapeyre
Copy link

Hi @kakshay21, the patch, tests and documentation looks fine to me, that's why I approved your pull request (please don't force push though next time as it makes all previous messages loose their context and your whole PR will get squash anyway).

A Python core developer will now make a final review (and may ask you other changes). There is very few of them and their attention can get stretched on many issues so it may take some time, don't worry about it.

@@ -0,0 +1,2 @@
Add property method to provide args and kwargs attributes on mock call
objects. Contributed by Kumar Akshay.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be better worded as "Add args and kwards propery to mock call objects".

form of a tuple: the first member is any ordered arguments the mock
was called with (or an empty tuple) and the second member is any
keyword arguments (or an empty dictionary).
form of a tuple: the first member is ``args`` which will be any ordered
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this to be "the first member, which can also be accessed through the args property", and likewise with kwargs below.

@kakshay21
Copy link
Contributor Author

Thanks! @cjw296

@@ -0,0 +1 @@
Add args and kwards propery to mock call objects. Contributed by Kumar Akshay.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typos in kwards and propery need fixing. args and kwargs should likely be surrounded by double back ticks, as in the docs, as it looks line NEWS is ReST too.

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@kakshay21
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@cjw296: please review the changes made to this pull request.

@cjw296 cjw296 merged commit b0df45e into python:master Mar 22, 2019
@miss-islington
Copy link
Contributor

Thanks @kakshay21 for the PR, and @cjw296 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @kakshay21 and @cjw296, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker b0df45e55dc8304bac0e3cad0225472b84190964 3.7

@cjw296
Copy link
Contributor

cjw296 commented Apr 1, 2019

@tirkarthi / @mariocj89 - would either of you be able to tackle the backport? I've not used cherry-picker before and this is the first time @miss-islington hasn't succeeded in the merge (which makes me a little scared!)

@tirkarthi
Copy link
Member

This more seems like an enhancement/feature to me. Is it worth backporting to 3.7?

@cjw296
Copy link
Contributor

cjw296 commented Apr 2, 2019

@tirkarthi - good call, sorry, brain not fully working. Guess that means there's nothing to do here?

@tirkarthi
Copy link
Member

tirkarthi commented Apr 2, 2019 •

No problem, I think the "needs backport to 3.7" label can be removed and the issue on tracker can be closed.

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.

7 participants