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

Function _setup_async_mock

Lib/unittest/mock.py:283–307  ·  view source on GitHub ↗
(mock)

Source from the content-addressed store, hash-verified

281
282
283def _setup_async_mock(mock):
284 mock._is_coroutine = asyncio.coroutines._is_coroutine
285 mock.await_count = 0
286 mock.await_args = None
287 mock.await_args_list = _CallList()
288
289 # Mock is not configured yet so the attributes are set
290 # to a function and then the corresponding mock helper function
291 # is called when the helper is accessed similar to _setup_func.
292 def wrapper(attr, /, *args, **kwargs):
293 return getattr(mock.mock, attr)(*args, **kwargs)
294
295 for attribute in ('assert_awaited',
296 'assert_awaited_once',
297 'assert_awaited_with',
298 'assert_awaited_once_with',
299 'assert_any_await',
300 'assert_has_awaits',
301 'assert_not_awaited'):
302
303 # setattr(mock, attribute, wrapper) causes late binding
304 # hence attribute will always be the last value in the loop
305 # Use partial(wrapper, attribute) to ensure the attribute is bound
306 # correctly.
307 setattr(mock, attribute, partial(wrapper, attribute))
308
309
310def _is_magic(name):

Callers 1

_set_async_signatureFunction · 0.85

Calls 2

partialClass · 0.90
_CallListClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…