]> granicus.if.org Git - python/commitdiff
bpo-28911: Clarify the behaviour of assert_called_once_with. (#254)
authorArne de Laat <arne@delaat.net>
Thu, 23 Feb 2017 16:16:56 +0000 (17:16 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 23 Feb 2017 16:16:56 +0000 (17:16 +0100)
(cherry picked from commit 9d56b34af2efc4e266bf3ae62da5cd2e422a42be)

Doc/library/unittest.mock.rst
Lib/unittest/mock.py

index 4b9dac402f961918c5aa471a13aa5e7b373a8ade..1169f0b5d3de66c7af3b5a8b005b010db03a793e 100644 (file)
@@ -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')
index 0512cca4e29ba472196907b9d4b7942794a416cf..9bc40bc2d154035a6a2c550dbc48431c17c63598 100644 (file)
@@ -795,8 +795,8 @@ class NonCallableMock(Base):
 
 
     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." %