Skip to content

bpo-38857: AsyncMock fix for awaitable values and StopIteration fix [3.8]#17269

Merged
lisroach merged 4 commits into
python:masterfrom
fried:AsyncMock
Nov 21, 2019
Merged

bpo-38857: AsyncMock fix for awaitable values and StopIteration fix [3.8]#17269
lisroach merged 4 commits into
python:masterfrom
fried:AsyncMock

Conversation

@fried

@fried fried commented Nov 20, 2019

Copy link
Copy Markdown
Contributor

AsyncMock can not Mock a callable that is expected to return an Awaitable, It awaits on it, which is Bug. This pull restructures AsyncMock to handle side_effects and wraps coroutines without having to await other values.

bpo-38859: Also since PEP 479, it is impossible to raise a StopIteration from a coroutine so the documented API for AsyncMock to return StopIteration on the exaustion of side_effects iterable is wrong. To match the Mock() API as close as possible we instead raise a StopAsyncIteration.
previous behavior was undocumented but was a RuntimeError.

https://bugs.python.org/issue38857

Comment thread Lib/unittest/mock.py Outdated
Comment thread Lib/unittest/test/testmock/testasync.py Outdated
Comment thread Lib/unittest/test/testmock/testasync.py Outdated
Comment thread Lib/unittest/test/testmock/testasync.py Outdated
@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@fried

fried commented Nov 20, 2019

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@lisroach: please review the changes made to this pull request.

@lisroach lisroach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Jason!

@lisroach
lisroach merged commit 046442d into python:master Nov 21, 2019
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @fried for the PR, and @lisroach for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry @fried and @lisroach, I had trouble checking out the 3.8 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 046442d02bcc6e848e71e93e47f6cde9e279e993 3.8

lisroach pushed a commit to lisroach/cpython that referenced this pull request Nov 21, 2019
… fix [3.8] (pythonGH-17269)

(cherry picked from commit 046442d)

Co-authored-by: Jason Fried <fried@fb.com>
@bedevere-bot

Copy link
Copy Markdown

GH-17304 is a backport of this pull request to the 3.8 branch.

asvetlov pushed a commit that referenced this pull request Nov 21, 2019
… fix [3.8] (GH-17269) (#17304)

(cherry picked from commit 046442d)

Co-authored-by: Jason Fried <fried@fb.com>
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
@fried
fried deleted the AsyncMock branch September 24, 2024 16:37
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.

5 participants