diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-11 21:17:48 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-11 21:17:48 (GMT) |
commit | 2c2a4e63d794eb55e9163322ea11b9765e9e0db5 (patch) | |
tree | 220e3dd3c738935ee81a2e80fa733e4f650c07a9 /Doc/library/unittest.mock.rst | |
parent | 82442b7022fbc438983eb4e973418357e3eec1e2 (diff) | |
download | cpython-2c2a4e63d794eb55e9163322ea11b9765e9e0db5.zip cpython-2c2a4e63d794eb55e9163322ea11b9765e9e0db5.tar.gz cpython-2c2a4e63d794eb55e9163322ea11b9765e9e0db5.tar.bz2 |
Add Mock.assert_called()
Issue #26323: Add assert_called() and assert_called_once() methods to
unittest.mock.Mock.
Diffstat (limited to 'Doc/library/unittest.mock.rst')
-rw-r--r-- | Doc/library/unittest.mock.rst | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 9a51194..c4dc4ed 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -259,6 +259,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) |