[3.8] bpo-38163: Child mocks detect their type as sync or async (GH-16471) (GH-16484)
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 5d32f88..488ab1c 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -997,8 +997,9 @@
# Any asynchronous magic becomes an AsyncMock
klass = AsyncMock
elif issubclass(_type, AsyncMockMixin):
- if _new_name in _all_sync_magics:
- # Any synchronous magic becomes a MagicMock
+ if (_new_name in _all_sync_magics or
+ self._mock_methods and _new_name in self._mock_methods):
+ # Any synchronous method on AsyncMock becomes a MagicMock
klass = MagicMock
else:
klass = AsyncMock