Skip to content

gh-156460: Await async callable side effects in AsyncMock - #156465

Draft
cananoo wants to merge 2 commits into
python:mainfrom
cananoo:fix/156460-asyncmock-callable
Draft

gh-156460: Await async callable side effects in AsyncMock#156465
cananoo wants to merge 2 commits into
python:mainfrom
cananoo:fix/156460-asyncmock-callable

Conversation

@cananoo

@cananoo cananoo commented Aug 27, 2026

Copy link
Copy Markdown

AsyncMock did not await callable instances with an asynchronous __call__
method when they were used as side_effect. It returned the coroutine created
by the callable instead, which could result in an unawaited coroutine warning.

This change recognizes an asynchronous __call__ method and awaits the
callable result, while preserving the existing behavior for synchronous
callables and ordinary awaitable return values.

Tests:

  • ./python.exe -m test test_unittest.testmock.testasync -j 0
  • ./python.exe -m test test_unittest -j 0
  • ./python.exe Tools/patchcheck/patchcheck.py

I used OpenAI Codex to assist with investigating and preparing this change,
and reviewed the resulting code, tests, and documentation before submission.

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant