From c9039535da8fdb876b36169ffba5eaa20ba8b6c6 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 18 May 2020 13:07:57 +0800 Subject: [PATCH] change: split load_test_file --- httprunner/loader.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/httprunner/loader.py b/httprunner/loader.py index 9cb18d9b..5dbdc61e 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -55,22 +55,29 @@ def _load_json_file(json_file: Text) -> Dict: return json_content -def load_testcase_file(testcase_file: Text) -> Tuple[Dict, TestCase]: - """load testcase file and validate with pydantic model""" - if not os.path.isfile(testcase_file): - raise exceptions.FileNotFound(f"testcase file not exists: {testcase_file}") +def load_test_file(test_file: Text) -> Dict: + """load testcase/testsuite file content""" + if not os.path.isfile(test_file): + raise exceptions.FileNotFound(f"test file not exists: {test_file}") - file_suffix = os.path.splitext(testcase_file)[1].lower() + file_suffix = os.path.splitext(test_file)[1].lower() if file_suffix == ".json": - testcase_content = _load_json_file(testcase_file) + test_file_content = _load_json_file(test_file) elif file_suffix in [".yaml", ".yml"]: - testcase_content = _load_yaml_file(testcase_file) + test_file_content = _load_yaml_file(test_file) else: # '' or other suffix raise exceptions.FileFormatError( - f"testcase file should be YAML/JSON format, invalid testcase file: {testcase_file}" + f"testcase/testsuite file should be YAML/JSON format, invalid format file: {test_file}" ) + return test_file_content + + +def load_testcase_file(testcase_file: Text) -> Tuple[Dict, TestCase]: + """load testcase file and validate with pydantic model""" + testcase_content = load_test_file(testcase_file) + try: # validate with pydantic TestCase model testcase_obj = TestCase.parse_obj(testcase_content)