diff options
author | Arne de Laat <arne@delaat.net> | 2017-02-23 16:16:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-02-23 16:16:56 (GMT) |
commit | fa30453568ae71861aa1928373bd76da4f3a33f6 (patch) | |
tree | facec143aeafd22d22b4c13044f846cae69a1bd0 /Doc/library | |
parent | 0246422b974b1a0c50dd30b0e1a1138674ef87a5 (diff) | |
download | cpython-fa30453568ae71861aa1928373bd76da4f3a33f6.zip cpython-fa30453568ae71861aa1928373bd76da4f3a33f6.tar.gz cpython-fa30453568ae71861aa1928373bd76da4f3a33f6.tar.bz2 |
bpo-28911: Clarify the behaviour of assert_called_once_with. (#254)
(cherry picked from commit 9d56b34af2efc4e266bf3ae62da5cd2e422a42be)
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/unittest.mock.rst | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 4b9dac4..1169f0b 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -275,14 +275,14 @@ the *new_callable* argument to :func:`patch`. .. method:: assert_called_once_with(*args, **kwargs) - Assert that the mock was called exactly once and with the specified - arguments. + Assert that the mock was called exactly once and that that call was + with the specified arguments. >>> mock = Mock(return_value=None) >>> mock('foo', bar='baz') >>> mock.assert_called_once_with('foo', bar='baz') - >>> mock('foo', bar='baz') - >>> mock.assert_called_once_with('foo', bar='baz') + >>> mock('other', bar='values') + >>> mock.assert_called_once_with('other', bar='values') Traceback (most recent call last): ... AssertionError: Expected 'mock' to be called once. Called 2 times. @@ -294,7 +294,8 @@ the *new_callable* argument to :func:`patch`. The assert passes if the mock has *ever* been called, unlike :meth:`assert_called_with` and :meth:`assert_called_once_with` that - only pass if the call is the most recent one. + only pass if the call is the most recent one, and in the case of + :meth:`assert_called_once_with` it must also be the only call. >>> mock = Mock(return_value=None) >>> mock(1, 2, arg='thing') |