diff -r 1ba0deb52223 -r f5bd331d0156 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,24 @@ (self._mock_name or 'mock', self.call_count)) raise AssertionError(msg) + def assert_called(_mock_self): + """assert that the mock was called at least once + """ + 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_once(_mock_self): + """assert that the mock was called only once. + """ + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (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. diff -r 1ba0deb52223 -r f5bd331d0156 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,25 @@ 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() + + #Issue26323 + def test_assert_called_once(self): + m = Mock() + m.hello() + m.hello() + with self.assertRaises(AssertionError): + m.hello.assert_called_once() + m.reset_mock() + m.hello() + m.hello.assert_called_once() + #Issue21256 printout of keyword args should be in deterministic order def test_sorted_call_signature(self): m = Mock()