在 Locust 中,我需要在使用 catch_response=True 验证响应时获得原始超时或连接错误
In Locust I need to get original timeout or connection error when using catch_response=True to validate response
关于如何验证请求的响应有很好的解释
https://docs.locust.io/en/stable/writing-a-locustfile.html#validating-responses
然而,有些情况下 status_code=0(连接错误或超时的情况)。
当 response.failure() 中发生时,我希望能够传递原始错误。
例如:
with self.client.get("/some_test_url/", catch_response=True) as response:
if response.status_code == 200 and _some_other_errors_checks_:
response.failure("Response is 200 but contain _some_error_")
if response.status_code == 0: # This is case of timeout or connection error
response.failure(????????)
您可以使用 response.error
属性 查看原始错误。
如果发生某些事情并且响应是错误响应或包含错误,您可以使用 response.raise_for_status()
引发原始错误,这将抛出响应的原始错误(如果存在)
关于如何验证请求的响应有很好的解释 https://docs.locust.io/en/stable/writing-a-locustfile.html#validating-responses
然而,有些情况下 status_code=0(连接错误或超时的情况)。 当 response.failure() 中发生时,我希望能够传递原始错误。 例如:
with self.client.get("/some_test_url/", catch_response=True) as response:
if response.status_code == 200 and _some_other_errors_checks_:
response.failure("Response is 200 but contain _some_error_")
if response.status_code == 0: # This is case of timeout or connection error
response.failure(????????)
您可以使用 response.error
属性 查看原始错误。
如果发生某些事情并且响应是错误响应或包含错误,您可以使用 response.raise_for_status()
引发原始错误,这将抛出响应的原始错误(如果存在)