diff --git a/httprunner/client.py b/httprunner/client.py index b7cf1447..bc31b5e1 100644 --- a/httprunner/client.py +++ b/httprunner/client.py @@ -12,6 +12,7 @@ from requests.exceptions import ( RequestException, ) +from httprunner.exceptions import NetworkFailure from httprunner.models import RequestData, ResponseData from httprunner.models import SessionData, ReqRespData from httprunner.utils import lower_dict_keys, omit_long_data @@ -184,16 +185,16 @@ class HttpSession(requests.Session): self.data.address.client_ip = client_ip self.data.address.client_port = client_port logger.debug(f"client IP: {client_ip}, Port: {client_port}") - except AttributeError: - logger.warning(f"failed to get client address info!") + except AttributeError as ex: + raise NetworkFailure(f"failed to get client address info: {ex}") try: server_ip, server_port = response.raw.connection.sock.getpeername() self.data.address.server_ip = server_ip self.data.address.server_port = server_port logger.debug(f"server IP: {server_ip}, Port: {server_port}") - except AttributeError: - logger.warning(f"failed to get server address info!") + except AttributeError as ex: + raise NetworkFailure(f"failed to get server address info: {ex}") # get length of the response content content_size = int(dict(response.headers).get("content-length") or 0) diff --git a/httprunner/exceptions.py b/httprunner/exceptions.py index 6559fd87..4f2e8eb6 100644 --- a/httprunner/exceptions.py +++ b/httprunner/exceptions.py @@ -27,6 +27,10 @@ class TeardownHooksFailure(MyBaseFailure): pass +class NetworkFailure(MyBaseFailure): + pass + + """ error type exceptions these exceptions will mark test as error """