changeset: 100232:9a70709e4612 bookmark: issue26323 tag: tip parent: 100221:1ba0deb52223 user: Amit Saha date: Fri Feb 12 10:06:52 2016 +1100 summary: fix for issue26323 diff -r 1ba0deb52223 -r 9a70709e4612 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Wed Feb 10 22:58:18 2016 +0000 +++ b/Lib/unittest/mock.py Fri Feb 12 10:06:52 2016 +1100 @@ -772,6 +772,15 @@ (self._mock_name or 'mock', self.call_count)) raise AssertionError(msg) + def assert_called(_mock_self): + """assert that the mock was called. + """ + self = _mock_self + if self.call_count == 0: + msg = ("Expected '%s' to have been called." % + self._mock_name or 'mock') + raise AssertionError(msg) + def assert_called_with(_mock_self, *args, **kwargs): """assert that the mock was called with the specified arguments. diff -r 1ba0deb52223 -r 9a70709e4612 Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py Wed Feb 10 22:58:18 2016 +0000 +++ b/Lib/unittest/test/testmock/testmock.py Fri Feb 12 10:06:52 2016 +1100 @@ -1222,6 +1222,14 @@ with self.assertRaises(AssertionError): m.hello.assert_not_called() + #Issue26323 + def test_assert_called(self): + m = Mock() + with self.assertRaises(AssertionError): + m.hello.assert_called() + m.hello() + m.hello.assert_called() + #Issue21256 printout of keyword args should be in deterministic order def test_sorted_call_signature(self): m = Mock()