【发布时间】:2020-02-11 20:42:59
【问题描述】:
为了测试目的,试图模拟 aiohttp.ClientSession 的响应
我的代码如下所示:
async def run_request(endpoint: str, **kwargs) -> dict:
async with aiohttp.ClientSession() as session:
async with session.post(endpoint, **kwargs) as response:
response_json = await response.json()
return {"response": response, "response_json": response_json}
我想用我想象的如下图来测试我的代码:
@patch("aiohttp.ClientSession.post", <something>)
def test_run_request(self):
我该怎么做?
【问题讨论】: