Autospec functions should propagate mock calls to parent GH-11273 (#12039)

(cherry picked from commit 9c3f284de598550be6687964c23fd7599e53b20e)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index c97ea79..5b8e744 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -320,6 +320,14 @@
 
 
 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