1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 01:25:34 +00:00

handle pytest-asyncio async def coroutines

This commit is contained in:
Thomas Grainger
2017-03-14 13:56:17 +00:00
parent 70f4707063
commit 7514d94262
7 changed files with 106 additions and 34 deletions

View File

@@ -1,7 +1,13 @@
import asyncio
import aiohttp
@asyncio.coroutine
def aiohttp_request(session, method, url, as_text, **kwargs):
response = yield from session.request(method, url, **kwargs) # NOQA: E999
return response, (yield from response.text()) if as_text else (yield from response.json()) # NOQA: E999
def aiohttp_request(loop, method, url, as_text, **kwargs):
with aiohttp.ClientSession(loop=loop) as session:
response = yield from session.request(method, url, **kwargs) # NOQA: E999
if as_text:
content = yield from response.text() # NOQA: E999
else:
content = yield from response.json() # NOQA: E999
return response, content