Commit bf67c4e1 authored by Michael Foord's avatar Michael Foord

Merge

parents 8fed4866 f27fa828
...@@ -276,7 +276,7 @@ the `new_callable` argument to `patch`. ...@@ -276,7 +276,7 @@ the `new_callable` argument to `patch`.
>>> mock.assert_called_once_with('foo', bar='baz') >>> mock.assert_called_once_with('foo', bar='baz')
Traceback (most recent call last): Traceback (most recent call last):
... ...
AssertionError: Expected to be called once. Called 2 times. AssertionError: Expected 'mock' to be called once. Called 2 times.
.. method:: assert_any_call(*args, **kwargs) .. method:: assert_any_call(*args, **kwargs)
...@@ -2020,7 +2020,7 @@ extremely handy: :meth:`~Mock.assert_called_with` and ...@@ -2020,7 +2020,7 @@ extremely handy: :meth:`~Mock.assert_called_with` and
>>> mock.assert_called_once_with(1, 2, 3) >>> mock.assert_called_once_with(1, 2, 3)
Traceback (most recent call last): Traceback (most recent call last):
... ...
AssertionError: Expected to be called once. Called 2 times. AssertionError: Expected 'mock' to be called once. Called 2 times.
Because mocks auto-create attributes on demand, and allow you to call them Because mocks auto-create attributes on demand, and allow you to call them
with arbitrary arguments, if you misspell one of these assert methods then with arbitrary arguments, if you misspell one of these assert methods then
......
...@@ -731,8 +731,8 @@ class NonCallableMock(Base): ...@@ -731,8 +731,8 @@ class NonCallableMock(Base):
arguments.""" arguments."""
self = _mock_self self = _mock_self
if not self.call_count == 1: if not self.call_count == 1:
msg = ("Expected to be called once. Called %s times." % msg = ("Expected '%s' to be called once. Called %s times." %
self.call_count) (self._mock_name or 'mock', self.call_count))
raise AssertionError(msg) raise AssertionError(msg)
return self.assert_called_with(*args, **kwargs) return self.assert_called_with(*args, **kwargs)
......
...@@ -463,6 +463,13 @@ class MockTest(unittest.TestCase): ...@@ -463,6 +463,13 @@ class MockTest(unittest.TestCase):
mock.assert_called_with) 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): def test__name__(self):
mock = Mock() mock = Mock()
self.assertRaises(AttributeError, lambda: mock.__name__) self.assertRaises(AttributeError, lambda: mock.__name__)
......
...@@ -31,6 +31,8 @@ Core and Builtins ...@@ -31,6 +31,8 @@ Core and Builtins
Library Library
------- -------
- Issue #15323: improve failure message of Mock.assert_called_once_with
- Issue #16064: unittest -m claims executable is "python", not "python3" - Issue #16064: unittest -m claims executable is "python", not "python3"
- Issue #12376: Pass on parameters in TextTestResult.__init__ super call - Issue #12376: Pass on parameters in TextTestResult.__init__ super call
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment