-
Notifications
You must be signed in to change notification settings - Fork 41
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
Why MagicMock can't be used in 'await' expression? #140
Comments
MagicMock is not awaitable, and the value returned by the call to
__aenter__ is unspecified, thus returns a MagicMock.
You need to tell to the mock of SomeAsyncClass what to return in a with
statement. In your case, I guess you expect something like "self" thus:
some_async_class.__aenter__.return_value = some_async_class()
Should work.
…On Thu, Aug 29, 2019, 16:22 Kazantcev Andrey ***@***.***> wrote:
For example, I have the same code
import asynctest
class SomeAsyncClass:
async def __aenter__(self):
pass
async def __aexit__(self, exc_type, exc_val, exc_tb):
pass
async def do_something(self):
pass
async def method_using_SomeAsyncClass():
async with SomeAsyncClass() as s:
return await s.do_something()
@asynctest.patch('test.SomeAsyncClass')
async def test_some_test(some_async_class):
res = await method_using_SomeAsyncClass()
And it fails with error: TypeError: object MagicMock can't be used in
'await' expression. Why and how to fix it?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#140?email_source=notifications&email_token=AABPWGBP6OXNYPCFFS4LTTTQG7LQ5A5CNFSM4ISC5BO2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HIG33MQ>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABPWGBXDOQ6BQBA47OKX4LQG7LQ5ANCNFSM4ISC5BOQ>
.
|
It's not work
doesn't work. Why MagicMock not pathced methods in SomeAsyncClass? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example, I have the same code
And it fails with error:
TypeError: object MagicMock can't be used in 'await' expression
. Why and how to fix it?The text was updated successfully, but these errors were encountered: