mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 19:47:14 +08:00
change: split load_test_file
This commit is contained in:
+15
-8
@@ -55,22 +55,29 @@ def _load_json_file(json_file: Text) -> Dict:
|
|||||||
return json_content
|
return json_content
|
||||||
|
|
||||||
|
|
||||||
def load_testcase_file(testcase_file: Text) -> Tuple[Dict, TestCase]:
|
def load_test_file(test_file: Text) -> Dict:
|
||||||
"""load testcase file and validate with pydantic model"""
|
"""load testcase/testsuite file content"""
|
||||||
if not os.path.isfile(testcase_file):
|
if not os.path.isfile(test_file):
|
||||||
raise exceptions.FileNotFound(f"testcase file not exists: {testcase_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":
|
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"]:
|
elif file_suffix in [".yaml", ".yml"]:
|
||||||
testcase_content = _load_yaml_file(testcase_file)
|
test_file_content = _load_yaml_file(test_file)
|
||||||
else:
|
else:
|
||||||
# '' or other suffix
|
# '' or other suffix
|
||||||
raise exceptions.FileFormatError(
|
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:
|
try:
|
||||||
# validate with pydantic TestCase model
|
# validate with pydantic TestCase model
|
||||||
testcase_obj = TestCase.parse_obj(testcase_content)
|
testcase_obj = TestCase.parse_obj(testcase_content)
|
||||||
|
|||||||
Reference in New Issue
Block a user