def test_error_handler_service_unavailable():
global tries
tries = 4
async def service_unavailable(**kwargs):
global tries
tries -= 1
if tries > 0:
response = MockResponse(status=503)
raise await exceptions.throw(response)
else:
return MockResponse()
with pytest.raises(exceptions.ServiceUnavailable):
with patch.object(asyncio, 'sleep', side_effect=dummy) as sleep:
await utils.error_handler(service_unavailable)()
assert sleep.called
await utils.error_handler(service_unavailable)()
评论列表
文章目录