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