-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Conversation
bpo-38859: AsyncMock can't raise StopIteration
…cMock as a side_effect/wraps function
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 |
Thanks for making the requested changes! @lisroach: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Jason!
Sorry @fried and @lisroach, I had trouble checking out the |
… fix [3.8] (pythonGH-17269) (cherry picked from commit 046442d) Co-authored-by: Jason Fried <fried@fb.com>
GH-17304 is a backport of this pull request to the 3.8 branch. |
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