Andrew Svetlov <andrew.svet...@gmail.com> added the comment:
Please keep in mind: not only asyncio can be used to execute async/await code. For example, trio has completely different implementation but utilizes async functions as well. Probably we need to customize it, maybe by inheriting AsyncioDocTestRunner from DocTestRunner base class. Also, using asyncio.run() for every line is not a good idea. asyncio.run() creates an new loop instance every time. Thus, the following doesn't work: >>> session = aiohttp.ClientSession() >>> async with session.get(url) as resp: ... text = await resp.text() The session is bound to loop, but the loop is changed by the next line. loop.run_until_complete() is not ideal too: it creates a new task every time. In AsyncioTestCase (https://github.com/python/cpython/pull/13386) I'm avoiding this problem by keeping a long-running task for saving the execution context between setup/teardown and test itself. ---------- nosy: +njs _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37006> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com