summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py4
-rw-r--r--Lib/unittest/test/testmock/testmock.py7
2 files changed, 9 insertions, 2 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 95570aa..324cf39 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -731,8 +731,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)
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index 64fd1a1..2c6f128 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -463,6 +463,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__)