MCPcopy Index your code
hub / github.com/python/cpython / _increment_mock_call

Method _increment_mock_call

Lib/unittest/mock.py:1182–1232  ·  view source on GitHub ↗
(self, /, *args, **kwargs)

Source from the content-addressed store, hash-verified

1180 return self._execute_mock_call(*args, **kwargs)
1181
1182 def _increment_mock_call(self, /, *args, **kwargs):
1183 self.called = True
1184
1185 # handle call_args
1186 # needs to be set here so assertions on call arguments pass before
1187 # execution in the case of awaited calls
1188 with NonCallableMock._lock:
1189 # Lock is used here so that call_args_list and call_count are
1190 # set atomically otherwise it is possible that by the time call_count
1191 # is set another thread may have appended to call_args_list.
1192 # The rest of this function relies on list.append being atomic and
1193 # skips locking.
1194 _call = _Call((args, kwargs), two=True)
1195 self.call_args = _call
1196 self.call_args_list.append(_call)
1197 self.call_count = len(self.call_args_list)
1198
1199 # initial stuff for method_calls:
1200 do_method_calls = self._mock_parent is not None
1201 method_call_name = self._mock_name
1202
1203 # initial stuff for mock_calls:
1204 mock_call_name = self._mock_new_name
1205 is_a_call = mock_call_name == '()'
1206 self.mock_calls.append(_Call(('', args, kwargs)))
1207
1208 # follow up the chain of mocks:
1209 _new_parent = self._mock_new_parent
1210 while _new_parent is not None:
1211
1212 # handle method_calls:
1213 if do_method_calls:
1214 _new_parent.method_calls.append(_Call((method_call_name, args, kwargs)))
1215 do_method_calls = _new_parent._mock_parent is not None
1216 if do_method_calls:
1217 method_call_name = _new_parent._mock_name + '.' + method_call_name
1218
1219 # handle mock_calls:
1220 this_mock_call = _Call((mock_call_name, args, kwargs))
1221 _new_parent.mock_calls.append(this_mock_call)
1222
1223 if _new_parent._mock_new_name:
1224 if is_a_call:
1225 dot = ''
1226 else:
1227 dot = '.'
1228 is_a_call = _new_parent._mock_new_name == '()'
1229 mock_call_name = _new_parent._mock_new_name + dot + mock_call_name
1230
1231 # follow the parental chain:
1232 _new_parent = _new_parent._mock_new_parent
1233
1234 def _execute_mock_call(self, /, *args, **kwargs):
1235 # separate from _increment_mock_call so that awaited functions are

Callers 2

__call__Method · 0.95
__call__Method · 0.80

Calls 2

_CallClass · 0.85
appendMethod · 0.45

Tested by 1

__call__Method · 0.64