diff -r 5376b3a168c8 Doc/library/unittest.mock.rst --- a/Doc/library/unittest.mock.rst Thu Dec 08 09:01:39 2016 -0800 +++ b/Doc/library/unittest.mock.rst Thu Dec 08 22:25:18 2016 +0100 @@ -303,26 +303,26 @@ .. 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. - .. method:: assert_any_call(*args, **kwargs) assert the mock has been called with the specified arguments. 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') diff -r 5376b3a168c8 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Thu Dec 08 09:01:39 2016 -0800 +++ b/Lib/unittest/mock.py Thu Dec 08 22:25:18 2016 +0100 @@ -815,8 +815,8 @@ def assert_called_once_with(_mock_self, *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.""" self = _mock_self if not self.call_count == 1: msg = ("Expected '%s' to be called once. Called %s times." %