bpo-38473: Handle autospecced functions and methods used with attach_… · python/cpython@71d2b33
@@ -1863,6 +1863,35 @@ def test_attach_mock_patch_autospec(self):
18631863self.assertEqual(mock_func.mock._extract_mock_name(), 'mock.child')
18641864186518651866+def test_attach_mock_patch_autospec_signature(self):
1867+with mock.patch(f'{__name__}.Something.meth', autospec=True) as mocked:
1868+manager = Mock()
1869+manager.attach_mock(mocked, 'attach_meth')
1870+obj = Something()
1871+obj.meth(1, 2, 3, d=4)
1872+manager.assert_has_calls([call.attach_meth(mock.ANY, 1, 2, 3, d=4)])
1873+obj.meth.assert_has_calls([call(mock.ANY, 1, 2, 3, d=4)])
1874+mocked.assert_has_calls([call(mock.ANY, 1, 2, 3, d=4)])
1875+1876+with mock.patch(f'{__name__}.something', autospec=True) as mocked:
1877+manager = Mock()
1878+manager.attach_mock(mocked, 'attach_func')
1879+something(1)
1880+manager.assert_has_calls([call.attach_func(1)])
1881+something.assert_has_calls([call(1)])
1882+mocked.assert_has_calls([call(1)])
1883+1884+with mock.patch(f'{__name__}.Something', autospec=True) as mocked:
1885+manager = Mock()
1886+manager.attach_mock(mocked, 'attach_obj')
1887+obj = Something()
1888+obj.meth(1, 2, 3, d=4)
1889+manager.assert_has_calls([call.attach_obj(),
1890+call.attach_obj().meth(1, 2, 3, d=4)])
1891+obj.meth.assert_has_calls([call(1, 2, 3, d=4)])
1892+mocked.assert_has_calls([call(), call().meth(1, 2, 3, d=4)])
1893+1894+18661895def test_attribute_deletion(self):
18671896for mock in (Mock(), MagicMock(), NonCallableMagicMock(),
18681897NonCallableMock()):