Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 21, 2019

Conversation

fried
Copy link
Contributor

@fried fried commented Nov 20, 2019

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

@bedevere-bot
Copy link

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
Copy link
Contributor Author

fried commented Nov 20, 2019

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

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

Copy link
Contributor

@lisroach lisroach left a comment

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
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
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

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