尝试模拟 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):
我怎样才能做到这一点?