From ae42f20745724e6a40af4b04ec6e28ea0d8ccd6b Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 4 Jun 2020 15:55:09 +0800 Subject: [PATCH] change: replace raise with exit 1 --- httprunner/compat.py | 13 +++++++------ tests/compat_test.py | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/httprunner/compat.py b/httprunner/compat.py index 2d7fd593..b0b0e740 100644 --- a/httprunner/compat.py +++ b/httprunner/compat.py @@ -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") diff --git a/tests/compat_test.py b/tests/compat_test.py index c44cd2a7..1b2dba3e 100644 --- a/tests/compat_test.py +++ b/tests/compat_test.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):