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