Commit 9c3f284d authored by Xtreak's avatar Xtreak Committed by Chris Withers

Autospec functions should propagate mock calls to parent GH-11273

parent f1b9abe3
......@@ -321,6 +321,14 @@ class _CallList(list):
def _check_and_set_parent(parent, value, name, new_name):
# function passed to create_autospec will have mock
# attribute attached to which parent must be set
if isinstance(value, FunctionTypes):
try:
value = value.mock
except AttributeError:
pass
if not _is_instance_mock(value):
return False
if ((value._mock_name or value._mock_new_name) or
......
......@@ -1830,5 +1830,18 @@ class MockTest(unittest.TestCase):
self.assertEqual(type(call.parent().parent), _Call)
def test_parent_propagation_with_create_autospec(self):
def foo(a, b):
pass
mock = Mock()
mock.child = create_autospec(foo)
mock.child(1, 2)
self.assertRaises(TypeError, mock.child, 1)
self.assertEqual(mock.mock_calls, [call.child(1, 2)])
if __name__ == '__main__':
unittest.main()
Calls to a child function created with :func:`unittest.mock.create_autospec`
should propagate to the parent. Patch by Karthikeyan Singaravelan.
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