Open tirkarthi opened 5 years ago
Worth noting that just changing to async-def's is not enough, as this will cause your current code base to produce RuntimeWarnings.
Reason being that failing to await an asyncio.coroutine-marked function's coroutine does not produce a warning in Python3.7, but failing to await an async-def coroutine will.
Python 3.7.3 (default, Jun 24 2019, 04:54:02)
[GCC 9.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>>
>>> @asyncio.coroutine
... def foo():
... pass
...
>>> f = foo()
>>> del f
>>>
>>> async def bar():
... pass
...
>>> b = bar()
>>> del b
__main__:1: RuntimeWarning: coroutine 'bar' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
I can put a pull request up with the main changes, but specifically, we have a few failures that appear to be because of this issue. Without knowing this code base any better, I am reluctant to do something that is against how you would like this code base to be designed :-)
It's relatively easy to silence "never awaited" warnings: just add a dummy callback. The tricky part is to understand why it was never awaited in the first place!
@nekokatt please publish a wip PR and maybe someone else will poke at it?
is this still needed? Python3.8 has AsyncMock in the standard lib now it appears
That's a good question :)
If I remember correctly, py3.8 AsyncMock
doesn't have all the features of the asynctest
... ,
Specifically, I suspect that py3.8 can't do asynctest.mock.patch("...", autospec=True)
.
Then again I haven't tried that yet 🤔
asyncio.coroutine is deprecated in python/cpython#13346 . Since 3.4 not supported maybe
async def
can be used? I ran pytest on CPython master and warnings as below :