summaryrefslogtreecommitdiff
path: root/Doc/library/unittest.mock.rst
diff options
context:
space:
mode:
authorMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
committerMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
commitda79bcf8ac7ae72218ab023e1ed54390bc1a3a27 (patch)
tree74845e2dbd9521d9748b9c32f1922f4123083bf3 /Doc/library/unittest.mock.rst
parente3c7e835bdfc97750eb9b7fc0ad2493108c2d438 (diff)
parent1fe806ac56f8b83694d24ab604eb695d00bc8497 (diff)
downloadcpython-da79bcf8ac7ae72218ab023e1ed54390bc1a3a27.tar.gz
Issue #29371: merge with 3.5
Diffstat (limited to 'Doc/library/unittest.mock.rst')
-rw-r--r--Doc/library/unittest.mock.rst40
1 files changed, 38 insertions, 2 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst
index 4b9dac402f..c6d0ec92b6 100644
--- a/Doc/library/unittest.mock.rst
+++ b/Doc/library/unittest.mock.rst
@@ -262,6 +262,34 @@ the *new_callable* argument to :func:`patch`.
used to set attributes on the mock after it is created. See the
:meth:`configure_mock` method for details.
+ .. method:: assert_called(*args, **kwargs)
+
+ Assert that the mock was called at least once.
+
+ >>> mock = Mock()
+ >>> mock.method()
+ <Mock name='mock.method()' id='...'>
+ >>> mock.method.assert_called()
+
+ .. versionadded:: 3.6
+
+ .. method:: assert_called_once(*args, **kwargs)
+
+ Assert that the mock was called exactly once.
+
+ >>> mock = Mock()
+ >>> mock.method()
+ <Mock name='mock.method()' id='...'>
+ >>> mock.method.assert_called_once()
+ >>> mock.method()
+ <Mock name='mock.method()' id='...'>
+ >>> mock.method.assert_called_once()
+ Traceback (most recent call last):
+ ...
+ AssertionError: Expected 'method' to have been called once. Called 2 times.
+
+ .. versionadded:: 3.6
+
.. method:: assert_called_with(*args, **kwargs)
@@ -339,7 +367,7 @@ the *new_callable* argument to :func:`patch`.
.. versionadded:: 3.5
- .. method:: reset_mock()
+ .. method:: reset_mock(*, return_value=False, side_effect=False)
The reset_mock method resets all the call attributes on a mock object:
@@ -351,12 +379,20 @@ the *new_callable* argument to :func:`patch`.
>>> mock.called
False
+ .. versionchanged:: 3.6
+ Added two keyword only argument to the reset_mock function.
+
This can be useful where you want to make a series of assertions that
reuse the same object. Note that :meth:`reset_mock` *doesn't* clear the
return value, :attr:`side_effect` or any child attributes you have
- set using normal assignment. Child mocks and the return value mock
+ set using normal assignment by default. In case you want to reset
+ *return_value* or :attr:`side_effect`, then pass the corresponding
+ parameter as ``True``. Child mocks and the return value mock
(if any) are reset as well.
+ .. note:: *return_value*, and :attr:`side_effect` are keyword only
+ argument.
+
.. method:: mock_add_spec(spec, spec_set=False)