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
Spy async bug introduced in Python 3.8.1 #178
Labels
Comments
adamcharnock
added a commit
to adamcharnock/lightbus
that referenced
this issue
Jan 12, 2020
If anyone needs a quick workaround, I'm using something like this: if sys.version_info >= (3, 8):
from unittest.mock import AsyncMock
redis_pool.grow = AsyncMock(wraps=redis_pool.grow)
else:
mocker.spy(redis_pool, "grow")
assert redis_pool.grow.call_count == 123
|
Hi @adamcharnock, Thanks for the report and workaround. Would you consider opening up a PR with this change? |
nicoddemus
added a commit
to frankie567/pytest-mock
that referenced
this issue
Jan 28, 2020
nicoddemus
added a commit
that referenced
this issue
Jan 28, 2020
Fix #178: handle spy on async functions
Thank you very much for this fix! Do you know when it will be released? 🙏 |
Thanks for the ping @k4nar! Just released |
Awesome, thank you for the responsiveness! Stay safe :) . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe bpo-38875 has introduced a bug in
mocker.spy()
. Spied coroutines are no longer awaited as they should be.This test highlights the issue:
It looks like
spy()
(specifically,wrapper()
defined withinspy()
) returns a coroutine and expectsunittest
'spatch()
do to the awaiting, rather than doing the awaiting itself. This worked until bpo-38875 changed this behaviour. Nowunittest
will no longer await retuned awaitables, rather it returns them.The text was updated successfully, but these errors were encountered: