asynctest icon indicating copy to clipboard operation
asynctest copied to clipboard

Wrapping object with asynctest.Mock does not turn async methods into CoroutineMock

Open Wesmania opened this issue 6 years ago • 1 comments

Sample interpreter session:

>>> import asynctest
>>> class Foo:
...     async def bar():
...         pass
... 
>>> f = Foo()
>>> m = asynctest.Mock(wraps=f)
>>> type(m.bar)
<class 'asynctest.mock.MagicMock'>
>>> m = asynctest.Mock(wraps=f, spec=f)
>>> type(m.bar)
<class 'asynctest.mock.CoroutineMock'>

I think just using wraps should turn wrapped object's coroutines into CoroutineMocks.

Wesmania avatar Oct 03 '18 18:10 Wesmania

Hm, it's more or less related to #31: currently, there is no mechanism to define how CoroutineMock should behave when it's return value is specified by a coroutine function.

When this behavior is defined, it probably makes sense to have the same behavior with wrapped objects.

Martiusweb avatar Apr 23 '19 17:04 Martiusweb