classification
Title: AsyncMock issue with awaitable return_value/side_effect/wraps
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, fried, lisroach
Priority: normal Keywords: patch

Created on 2019-11-19 23:04 by fried, last changed 2019-11-21 18:17 by lisroach. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17269 merged fried, 2019-11-20 00:38
PR 17304 merged lisroach, 2019-11-21 00:38
Messages (3)
msg357000 - (view) Author: Jason Fried (fried) * Date: 2019-11-19 23:04
If you are trying to use AsyncMock to mock a coroutine that returns awaitable objects, AsyncMock awaits on those objects instead of returning them as is. 

Example:
  mock = AsyncMock(return_value=asyncio.Future())
  v = await mock()  # blocks on trying to await the future

Expected:
  mock = AsyncMock(return_value=asyncio.Future())
  v = await mock()
  assert isisnstance(v, asyncio.Future)

This problem affects side_effects and wraps.
msg357116 - (view) Author: Lisa Roach (lisroach) * (Python committer) Date: 2019-11-21 00:27
New changeset 046442d02bcc6e848e71e93e47f6cde9e279e993 by Lisa Roach (Jason Fried) in branch 'master':
bpo-38857: AsyncMock fix for awaitable values and StopIteration fix [3.8] (GH-17269)
https://github.com/python/cpython/commit/046442d02bcc6e848e71e93e47f6cde9e279e993
msg357190 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-11-21 18:14
New changeset b2744c1be73f5af0d2dc4b952389efc90c8de94e by Andrew Svetlov (Lisa Roach) in branch '3.8':
[3.8] bpo-38857: AsyncMock fix for awaitable values and StopIteration fix [3.8] (GH-17269) (#17304)
https://github.com/python/cpython/commit/b2744c1be73f5af0d2dc4b952389efc90c8de94e
History
Date User Action Args
2019-11-21 18:17:51lisroachsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-11-21 18:14:36asvetlovsetnosy: + asvetlov
messages: + msg357190
2019-11-21 00:38:41lisroachsetpull_requests: + pull_request16796
2019-11-21 00:27:56lisroachsetmessages: + msg357116
2019-11-20 00:38:18friedsetkeywords: + patch
stage: patch review
pull_requests: + pull_request16761
2019-11-20 00:14:48friedsettype: behavior
2019-11-19 23:04:13friedcreate