[issue38122] AsyncMock force always creating an AsyncMock for child mocks
Karthikeyan Singaravelan
report at bugs.python.org
Wed Sep 11 13:41:45 EDT 2019
Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:
Sorry, is there an example of this use case. I went through the issue but have trouble understanding it since there are different suggestions. I guess child mock is always an AsyncMock irrespective of sync/async as I understand. We already had some reports over detecting async while patching to return AsyncMock and also had to document it to the users along with covering different ways of async functions.
from unittest.mock import AsyncMock
class Foo:
def foo(self):
pass
async def bar(self):
pass
m = AsyncMock(Foo)
f = m()
print(m.foo)
print(m.bar)
$ python3.8 /tmp/bar.py
<AsyncMock name='mock.foo' id='4313089744'>
<AsyncMock name='mock.bar' id='4313395696'>
sys:1: RuntimeWarning: coroutine 'AsyncMockMixin._mock_call' was never awaited
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38122>
_______________________________________
More information about the Python-bugs-list
mailing list