mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 06:23:52 +08:00
fix: handle exception for loaded invalid format test content
This commit is contained in:
@@ -31,12 +31,10 @@ def load_har_log_entries(file_path):
|
|||||||
with io.open(file_path, "r+", encoding="utf-8-sig") as f:
|
with io.open(file_path, "r+", encoding="utf-8-sig") as f:
|
||||||
try:
|
try:
|
||||||
content_json = json.loads(f.read())
|
content_json = json.loads(f.read())
|
||||||
|
return content_json["log"]["entries"]
|
||||||
except (TypeError, JSONDecodeError) as ex:
|
except (TypeError, JSONDecodeError) as ex:
|
||||||
logger.error(f"failed to load HAR file {file_path}: {ex}")
|
logger.error(f"failed to load HAR file {file_path}: {ex}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
|
||||||
return content_json["log"]["entries"]
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.error(f"log entries not found in HAR file: {content_json}")
|
logger.error(f"log entries not found in HAR file: {content_json}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from typing import Text, List, Tuple, Dict, Set, NoReturn
|
from typing import Text, List, Tuple, Dict, Set, NoReturn
|
||||||
|
|
||||||
@@ -428,12 +429,19 @@ def __make(tests_path: Text) -> NoReturn:
|
|||||||
logger.warning(ex)
|
logger.warning(ex)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if not isinstance(test_content, Dict):
|
||||||
|
raise exceptions.FileFormatError(
|
||||||
|
f"test content not in dict format: {test_content}"
|
||||||
|
)
|
||||||
|
|
||||||
# api in v2 format, convert to v3 testcase
|
# api in v2 format, convert to v3 testcase
|
||||||
if "request" in test_content:
|
if "request" in test_content and "name" in test_content:
|
||||||
test_content = ensure_testcase_v3_api(test_content)
|
test_content = ensure_testcase_v3_api(test_content)
|
||||||
|
|
||||||
if not (isinstance(test_content, Dict) and "config" in test_content):
|
if "config" not in test_content:
|
||||||
raise exceptions.FileFormatError("Invalid testcase/testsuite v2/v3 format!")
|
raise exceptions.FileFormatError(
|
||||||
|
f"miss config part in testcase/testsuite: {test_content}"
|
||||||
|
)
|
||||||
|
|
||||||
test_content.setdefault("config", {})["path"] = test_file
|
test_content.setdefault("config", {})["path"] = test_file
|
||||||
|
|
||||||
@@ -465,7 +473,12 @@ def main_make(tests_paths: List[Text]) -> List[Text]:
|
|||||||
if not os.path.isabs(tests_path):
|
if not os.path.isabs(tests_path):
|
||||||
tests_path = os.path.join(os.getcwd(), tests_path)
|
tests_path = os.path.join(os.getcwd(), tests_path)
|
||||||
|
|
||||||
__make(tests_path)
|
try:
|
||||||
|
__make(tests_path)
|
||||||
|
except exceptions.MyBaseError as ex:
|
||||||
|
logger.error(ex)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
__ensure_project_meta_files(tests_path)
|
__ensure_project_meta_files(tests_path)
|
||||||
|
|
||||||
# format pytest files
|
# format pytest files
|
||||||
|
|||||||
Reference in New Issue
Block a user