用python编写一些单元测试,已经将其简化为一些函数来关注这个问题
这是两个函数
def function_to_throw_http_error():
logger.info("function_to_throw_http_error")
def function_to_catch_http_error():
try:
function_to_throw_http_error()
except HTTPError as http_err:
logger.error(f"HTTP error occurred external service: {http_err}")
return {"statusCode": http_err.response.status_code, "body": http_err.response.reason}
这是什么
@patch(
"functions.my_file.function_to_throw_http_error", Mock(side_effect=HTTPError(Mock(status_code=404), 'error')),
)
def test_catching_http_error_reposnse(self):
response = function_to_catch_http_error()
self.assertTrue('error' in str(response))
但是当我运行测试时,我得到了以下错误
> return {"statusCode": http_err.response.status_code, "body": http_err.response.reason}
E AttributeError: 'NoneType' object has no attribute 'status_code'
相关问题 更多 >
编程相关推荐