Create the child mocks for attributes and return value. By default child mocks will be the same type as the parent. Subclasses of Mock may want to override this to customize the way child mocks are made. For non-callable mocks the callable variant will be used (rathe
(self, /, **kw)
| 1060 | |
| 1061 | |
| 1062 | def _get_child_mock(self, /, **kw): |
| 1063 | """Create the child mocks for attributes and return value. |
| 1064 | By default child mocks will be the same type as the parent. |
| 1065 | Subclasses of Mock may want to override this to customize the way |
| 1066 | child mocks are made. |
| 1067 | |
| 1068 | For non-callable mocks the callable variant will be used (rather than |
| 1069 | any custom subclass).""" |
| 1070 | if self._mock_sealed: |
| 1071 | attribute = f".{kw['name']}" if "name" in kw else "()" |
| 1072 | mock_name = self._extract_mock_name() + attribute |
| 1073 | raise AttributeError(mock_name) |
| 1074 | |
| 1075 | _new_name = kw.get("_new_name") |
| 1076 | if _new_name in self.__dict__['_spec_asyncs']: |
| 1077 | return AsyncMock(**kw) |
| 1078 | |
| 1079 | _type = type(self) |
| 1080 | if issubclass(_type, MagicMock) and _new_name in _async_method_magics: |
| 1081 | # Any asynchronous magic becomes an AsyncMock |
| 1082 | klass = AsyncMock |
| 1083 | elif issubclass(_type, AsyncMockMixin): |
| 1084 | if (_new_name in _all_sync_magics or |
| 1085 | self._mock_methods and _new_name in self._mock_methods): |
| 1086 | # Any synchronous method on AsyncMock becomes a MagicMock |
| 1087 | klass = MagicMock |
| 1088 | else: |
| 1089 | klass = AsyncMock |
| 1090 | elif not issubclass(_type, CallableMixin): |
| 1091 | if issubclass(_type, NonCallableMagicMock): |
| 1092 | klass = MagicMock |
| 1093 | elif issubclass(_type, NonCallableMock): |
| 1094 | klass = Mock |
| 1095 | else: |
| 1096 | klass = _type.__mro__[1] |
| 1097 | return klass(**kw) |
| 1098 | |
| 1099 | |
| 1100 | def _calls_repr(self): |
no test coverage detected