summaryrefslogtreecommitdiff
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-11 22:17:48 +0100
committerVictor Stinner <victor.stinner@gmail.com>2016-03-11 22:17:48 +0100
commit2c2a4e63d794eb55e9163322ea11b9765e9e0db5 (patch)
tree220e3dd3c738935ee81a2e80fa733e4f650c07a9 /Lib/unittest/test
parent82442b7022fbc438983eb4e973418357e3eec1e2 (diff)
downloadcpython-git-2c2a4e63d794eb55e9163322ea11b9765e9e0db5.tar.gz
Add Mock.assert_called()
Issue #26323: Add assert_called() and assert_called_once() methods to unittest.mock.Mock.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/testmock/testmock.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index 2a6069f66a..b2d9acbc12 100644
--- 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()
+ def test_assert_called(self):
+ m = Mock()
+ with self.assertRaises(AssertionError):
+ m.hello.assert_called()
+ m.hello()
+ m.hello.assert_called()
+
+ m.hello()
+ m.hello.assert_called()
+
+ def test_assert_called_once(self):
+ m = Mock()
+ with self.assertRaises(AssertionError):
+ m.hello.assert_called_once()
+ m.hello()
+ m.hello.assert_called_once()
+
+ m.hello()
+ with self.assertRaises(AssertionError):
+ m.hello.assert_called_once()
+
#Issue21256 printout of keyword args should be in deterministic order
def test_sorted_call_signature(self):
m = Mock()