diff options
author | Kushal Das <kushaldas@gmail.com> | 2014-04-17 01:36:14 +0530 |
---|---|---|
committer | Kushal Das <kushaldas@gmail.com> | 2014-04-17 01:36:14 +0530 |
commit | 8af9db3e4fa17fb7add3f904a19d816f7787ee1c (patch) | |
tree | 18ffd4eb5f027edb0648bd32088bb455ef2a3c59 /Lib/unittest/mock.py | |
parent | 8c14534df6c7bd561fac31985fba60306e181265 (diff) | |
download | cpython-8af9db3e4fa17fb7add3f904a19d816f7787ee1c.tar.gz cpython-8af9db3e4fa17fb7add3f904a19d816f7787ee1c.zip |
Closes Issue 21262: New method assert_not_called for Mock.
It raises AssertionError if the mock has been called.
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 48e7dd078f2..6c00bc66f8f 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -758,6 +758,14 @@ class NonCallableMock(Base): else: return _call + def assert_not_called(_mock_self, *args, **kwargs): + """assert that the mock was never called. + """ + self = _mock_self + if self.call_count != 0: + msg = ("Expected '%s' to not have been called. 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. |