Skip to content
Snippets Groups Projects
Commit 7ea94088 authored by Michael Foord's avatar Michael Foord Committed by Robert Collins
Browse files

Closes issue 15323. Improve failure message of Mock.assert_called_once_with

parent dfb22117
No related branches found
No related tags found
No related merge requests found
- Issue #15323: improve failure message of Mock.assert_called_once_with
- Issue #14857: fix regression in references to PEP 3135 implicit __class__
closure variable (Reopens issue #12370)
......
......@@ -864,8 +864,8 @@ class NonCallableMock(Base):
arguments."""
self = _mock_self
if not self.call_count == 1:
msg = ("Expected to be called once. Called %s times." %
self.call_count)
msg = ("Expected '%s' to be called once. Called %s times." %
(self._mock_name or 'mock', self.call_count))
raise AssertionError(msg)
return self.assert_called_with(*args, **kwargs)
......
......@@ -486,6 +486,13 @@ class MockTest(unittest.TestCase):
mock.assert_called_with)
def test_assert_called_once_with_message(self):
mock = Mock(name='geoffrey')
self.assertRaisesRegex(AssertionError,
r"Expected 'geoffrey' to be called once\.",
mock.assert_called_once_with)
def test__name__(self):
mock = Mock()
self.assertRaises(AttributeError, lambda: mock.__name__)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment