mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
Closes Issue 21262: New method assert_not_called for Mock.
It raises AssertionError if the mock has been called.
This commit is contained in:
parent
8c14534df6
commit
8af9db3e4f
4 changed files with 34 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue