summaryrefslogtreecommitdiff
path: root/Lib/unittest/test/testmock/testmock.py
diff options
context:
space:
mode:
authorAbraham Toriz Cruz <awonderfulcode@gmail.com>2019-09-17 06:16:08 -0500
committerPablo Galindo <Pablogsal@gmail.com>2019-09-17 12:16:08 +0100
commit5f5f11faf9de0d8dcbe1a8a4eb35d2a4232d6eaa (patch)
tree18cdf4ee14ec18b596aa1ea5f6fb4ad60bccc508 /Lib/unittest/test/testmock/testmock.py
parent219fb9d65ef7e5363eccc9dde0988bb085db1c86 (diff)
downloadcpython-git-5f5f11faf9de0d8dcbe1a8a4eb35d2a4232d6eaa.tar.gz
bpo-37828: Fix default mock_name in unittest.mock.assert_called error (GH-16166)
In the format string for assert_called the evaluation order is incorrect and hence for mock's without name, 'None' is printed whereas it should be 'mock' like for other messages. The error message is ("Expected '%s' to have been called." % self._mock_name or 'mock').
Diffstat (limited to 'Lib/unittest/test/testmock/testmock.py')
-rw-r--r--Lib/unittest/test/testmock/testmock.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index 581afaaeb8..2bafa8266b 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -396,6 +396,14 @@ class MockTest(unittest.TestCase):
_check(mock)
+ def test_assert_called_exception_message(self):
+ msg = "Expected '{0}' to have been called"
+ with self.assertRaisesRegex(AssertionError, msg.format('mock')):
+ Mock().assert_called()
+ with self.assertRaisesRegex(AssertionError, msg.format('test_name')):
+ Mock(name="test_name").assert_called()
+
+
def test_assert_called_once_with(self):
mock = Mock()
mock()