mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:59:44 +08:00
change: capture exception with sentry
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
__version__ = "3.0.7"
|
||||
__version__ = "3.0.8"
|
||||
__description__ = "One-stop solution for HTTP(S) testing."
|
||||
|
||||
from httprunner.runner import HttpRunner
|
||||
|
||||
@@ -11,6 +11,7 @@ from requests.exceptions import (
|
||||
MissingSchema,
|
||||
RequestException,
|
||||
)
|
||||
from sentry_sdk import capture_exception
|
||||
|
||||
from httprunner.schema import RequestData, ResponseData
|
||||
from httprunner.schema import SessionData, ReqRespData
|
||||
@@ -45,15 +46,15 @@ def get_req_resp_record(resp_obj: Response) -> ReqRespData:
|
||||
request_body = resp_obj.request.body
|
||||
try:
|
||||
request_body = json.loads(request_body)
|
||||
except json.JSONDecodeError:
|
||||
except json.JSONDecodeError as ex:
|
||||
# str: Unexpected UTF-8 BOM (decode using utf-8-sig)
|
||||
pass
|
||||
except UnicodeDecodeError:
|
||||
capture_exception(ex)
|
||||
except UnicodeDecodeError as ex:
|
||||
# bytes/bytearray: request body in protobuf
|
||||
pass
|
||||
except TypeError:
|
||||
capture_exception(ex)
|
||||
except TypeError as ex:
|
||||
# neither str nor bytes/bytearray, e.g. None
|
||||
pass
|
||||
capture_exception(ex)
|
||||
|
||||
if request_body:
|
||||
request_content_type = lower_dict_keys(request_headers).get("content-type")
|
||||
|
||||
@@ -5,6 +5,7 @@ import sys
|
||||
import urllib.parse as urlparse
|
||||
|
||||
from loguru import logger
|
||||
from sentry_sdk import capture_exception
|
||||
|
||||
from httprunner.ext.har2case import utils
|
||||
from httprunner.make import make_testcase, format_pytest_with_black
|
||||
@@ -166,8 +167,8 @@ class HarParser(object):
|
||||
try:
|
||||
post_data = json.loads(post_data)
|
||||
request_data_key = "json"
|
||||
except JSONDecodeError:
|
||||
pass
|
||||
except JSONDecodeError as ex:
|
||||
capture_exception(ex)
|
||||
elif mimeType.startswith("application/x-www-form-urlencoded"):
|
||||
post_data = utils.convert_x_www_form_urlencoded_to_dict(post_data)
|
||||
else:
|
||||
@@ -237,7 +238,8 @@ class HarParser(object):
|
||||
|
||||
try:
|
||||
resp_content_json = json.loads(content)
|
||||
except JSONDecodeError:
|
||||
except JSONDecodeError as ex:
|
||||
capture_exception(ex)
|
||||
logger.warning(
|
||||
"response content can not be loaded as json: {}".format(
|
||||
content.encode("utf-8")
|
||||
@@ -334,7 +336,12 @@ class HarParser(object):
|
||||
logger.info(f"Start to generate testcase from {self.har_file_path}")
|
||||
harfile = os.path.splitext(self.har_file_path)[0]
|
||||
|
||||
testcase = self._make_testcase()
|
||||
try:
|
||||
testcase = self._make_testcase()
|
||||
except Exception as ex:
|
||||
capture_exception(ex)
|
||||
raise
|
||||
|
||||
logger.debug("prepared testcase: {}".format(testcase))
|
||||
|
||||
if file_type == "JSON":
|
||||
|
||||
@@ -6,6 +6,7 @@ from urllib.parse import unquote
|
||||
|
||||
import yaml
|
||||
from loguru import logger
|
||||
from sentry_sdk import capture_exception
|
||||
|
||||
|
||||
def load_har_log_entries(file_path):
|
||||
@@ -32,7 +33,8 @@ def load_har_log_entries(file_path):
|
||||
try:
|
||||
content_json = json.loads(f.read())
|
||||
return content_json["log"]["entries"]
|
||||
except (KeyError, TypeError, JSONDecodeError):
|
||||
except (KeyError, TypeError, JSONDecodeError) as ex:
|
||||
capture_exception(ex)
|
||||
logger.error("HAR file content error: {}".format(file_path))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from typing import Text, List, Tuple, Dict, Set, NoReturn
|
||||
|
||||
import jinja2
|
||||
from loguru import logger
|
||||
from sentry_sdk import capture_exception
|
||||
|
||||
from httprunner import exceptions, __version__
|
||||
from httprunner.compat import ensure_testcase_v3_api, ensure_testcase_v3
|
||||
@@ -131,6 +132,7 @@ def format_pytest_with_black(*python_paths: Text) -> NoReturn:
|
||||
try:
|
||||
subprocess.run(["black", *python_paths])
|
||||
except subprocess.CalledProcessError as ex:
|
||||
capture_exception(ex)
|
||||
logger.error(ex)
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import builtins
|
||||
import re
|
||||
from typing import Any, Set, Text, Callable, List, Dict
|
||||
|
||||
from sentry_sdk import capture_exception
|
||||
|
||||
from httprunner import loader, utils, exceptions
|
||||
from httprunner.schema import VariablesMapping, FunctionsMapping
|
||||
|
||||
@@ -70,7 +72,8 @@ def regex_findall_variables(content: Text) -> List[Text]:
|
||||
for var_tuple in variable_regex_compile.findall(content):
|
||||
vars_list.append(var_tuple[0] or var_tuple[1])
|
||||
return vars_list
|
||||
except TypeError:
|
||||
except TypeError as ex:
|
||||
capture_exception(ex)
|
||||
return []
|
||||
|
||||
|
||||
@@ -102,7 +105,8 @@ def regex_findall_functions(content: Text) -> List[Text]:
|
||||
"""
|
||||
try:
|
||||
return function_regex_compile.findall(content)
|
||||
except TypeError:
|
||||
except TypeError as ex:
|
||||
capture_exception(ex)
|
||||
return []
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "httprunner"
|
||||
version = "3.0.7"
|
||||
version = "3.0.8"
|
||||
description = "One-stop solution for HTTP(S) testing."
|
||||
license = "Apache-2.0"
|
||||
readme = "README.md"
|
||||
|
||||
Reference in New Issue
Block a user