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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user