diff options
author | Kumar Akshay <k.akshay9721@gmail.com> | 2019-03-22 08:10:40 (GMT) |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2019-03-22 08:10:40 (GMT) |
commit | b0df45e55dc8304bac0e3cad0225472b84190964 (patch) | |
tree | 14726255b39569c2d0b748bc7393ce2ce2423128 /Doc/library/unittest.mock.rst | |
parent | 40b6907b377cfc8c4743007894364ac8c5a1c113 (diff) | |
download | cpython-b0df45e55dc8304bac0e3cad0225472b84190964.zip cpython-b0df45e55dc8304bac0e3cad0225472b84190964.tar.gz cpython-b0df45e55dc8304bac0e3cad0225472b84190964.tar.bz2 |
bpo-21269: Provide args and kwargs attributes on mock call objects GH11807
Diffstat (limited to 'Doc/library/unittest.mock.rst')
-rw-r--r-- | Doc/library/unittest.mock.rst | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index ff7a54c..ed00ee6 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -609,9 +609,11 @@ the *new_callable* argument to :func:`patch`. This is either ``None`` (if the mock hasn't been called), or the arguments that the mock was last called with. This will be in the - 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, which can also be accessed through + the ``args`` property, is any ordered arguments the mock was + called with (or an empty tuple) and the second member, which can + also be accessed through the ``kwargs`` property, is any keyword + arguments (or an empty dictionary). >>> mock = Mock(return_value=None) >>> print(mock.call_args) @@ -626,9 +628,17 @@ the *new_callable* argument to :func:`patch`. call(3, 4) >>> mock.call_args == ((3, 4),) True + >>> mock.call_args.args + (3, 4) + >>> mock.call_args.kwargs + {} >>> mock(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args call(3, 4, 5, key='fish', next='w00t!') + >>> mock.call_args.args + (3, 4, 5) + >>> mock.call_args.kwargs + {'key': 'fish', 'next': 'w00t!'} :attr:`call_args`, along with members of the lists :attr:`call_args_list`, :attr:`method_calls` and :attr:`mock_calls` are :data:`call` objects. @@ -1987,14 +1997,13 @@ arguments are a dictionary: >>> m = MagicMock(return_value=None) >>> m(1, 2, 3, arg='one', arg2='two') >>> kall = m.call_args - >>> args, kwargs = kall - >>> args + >>> kall.args (1, 2, 3) - >>> kwargs + >>> kall.kwargs {'arg': 'one', 'arg2': 'two'} - >>> args is kall[0] + >>> kall.args is kall[0] True - >>> kwargs is kall[1] + >>> kall.kwargs is kall[1] True >>> m = MagicMock() |