cpython: bd75f8d34f97 (original) (raw)

Mercurial > cpython

changeset 100493:bd75f8d34f97

Add Mock.assert_called() Issue #26323: Add assert_called() and assert_called_once() methods to unittest.mock.Mock. [#26323]

Victor Stinner victor.stinner@gmail.com
date Fri, 11 Mar 2016 22:17:48 +0100
parents 40d92c92eb6e
children 291d47954618
files Doc/library/unittest.mock.rst Doc/whatsnew/3.6.rst Lib/unittest/mock.py Lib/unittest/test/testmock/testmock.py Misc/ACKS Misc/NEWS
diffstat 6 files changed, 83 insertions(+), 0 deletions(-)[+] [-] Doc/library/unittest.mock.rst 28 Doc/whatsnew/3.6.rst 12 Lib/unittest/mock.py 18 Lib/unittest/test/testmock/testmock.py 21 Misc/ACKS 1 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -259,6 +259,34 @@ the new_callable argument to :func:pa[](#l1.3) used to set attributes on the mock after it is created. See the[](#l1.4) :meth:configure_mock` method for details.

+

+

+

+

+

+

+

+ .. method:: assert_called_with(*args, **kwargs)

--- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -161,6 +161,18 @@ telnetlib Stéphane Wirtel in :issue:25485). +unittest.mock +------------- + +The :class:~unittest.mock.Mock class has the following improvements: + +* Two new methods, :meth:`Mock.assert_called()

--- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -772,6 +772,24 @@ class NonCallableMock(Base): (self._mock_name or 'mock', self.call_count)) raise AssertionError(msg)

+

+ def assert_called_with(_mock_self, *args, **kwargs): """assert that the mock was called with the specified arguments.

--- a/Lib/unittest/test/testmock/testmock.py +++ b/Lib/unittest/test/testmock/testmock.py @@ -1222,6 +1222,27 @@ class MockTest(unittest.TestCase): with self.assertRaises(AssertionError): m.hello.assert_not_called()

+

+

+

+ #Issue21256 printout of keyword args should be in deterministic order def test_sorted_call_signature(self): m = Mock()

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -1267,6 +1267,7 @@ Bernt Røskar Brenna Constantina S. Patrick Sabin Sébastien Sablé +Amit Saha Suman Saha Hajime Saitou George Sakkis

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -201,6 +201,9 @@ Core and Builtins Library ------- +- Issue #26323: Add Mock.assert_called() and Mock.assert_called_once()