mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
change: replace raise with exit 1
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
This module handles compatibility issues between testcase format v2 and v3.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
from typing import List, Dict, Text, Union
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from httprunner import exceptions
|
||||
from httprunner.loader import load_project_meta
|
||||
from httprunner.utils import sort_dict_by_custom_order
|
||||
|
||||
@@ -28,9 +28,8 @@ def convert_jmespath(raw: Text) -> Text:
|
||||
elif item.isdigit():
|
||||
# convert lst.0.name to lst[0].name
|
||||
if len(raw_list) == 0:
|
||||
raise exceptions.FileFormatError(
|
||||
f"Invalid jmespath: {raw}, jmespath should startswith headers/body/status_code/cookies"
|
||||
)
|
||||
logger.error(f"Invalid jmespath: {raw}")
|
||||
sys.exit(1)
|
||||
|
||||
last_item = raw_list.pop()
|
||||
item = f"{last_item}[{item}]"
|
||||
@@ -60,7 +59,8 @@ def convert_extractors(extractors: Union[List, Dict]) -> Dict:
|
||||
elif isinstance(extractors, Dict):
|
||||
v3_extractors = extractors
|
||||
else:
|
||||
raise exceptions.FileFormatError(f"Invalid extractor: {extractors}")
|
||||
logger.error(f"Invalid extractor: {extractors}")
|
||||
sys.exit(1)
|
||||
|
||||
for k, v in v3_extractors.items():
|
||||
v3_extractors[k] = convert_jmespath(v)
|
||||
@@ -207,7 +207,8 @@ def generate_conftest_for_summary(args: List):
|
||||
# FIXME: several test paths maybe specified
|
||||
break
|
||||
else:
|
||||
raise exceptions.FileNotFound(f"No test path specified!")
|
||||
logger.error(f"No valid test path specified! \nargs: {args}")
|
||||
sys.exit(1)
|
||||
|
||||
project_meta = load_project_meta(test_path)
|
||||
conftest_path = os.path.join(project_meta.PWD, "conftest.py")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from httprunner import compat, exceptions
|
||||
from httprunner import compat
|
||||
|
||||
|
||||
class TestCompat(unittest.TestCase):
|
||||
@@ -19,7 +19,7 @@ class TestCompat(unittest.TestCase):
|
||||
compat.convert_jmespath("body.data.buildings.0.building_id"),
|
||||
"body.data.buildings[0].building_id",
|
||||
)
|
||||
with self.assertRaises(exceptions.FileFormatError):
|
||||
with self.assertRaises(SystemExit):
|
||||
compat.convert_jmespath("2.buildings.0.building_id")
|
||||
|
||||
def test_convert_extractors(self):
|
||||
|
||||
Reference in New Issue
Block a user