refactor: make testcase

This commit is contained in:
debugtalk
2020-05-18 15:55:38 +08:00
parent c9039535da
commit bd71a23843
5 changed files with 63 additions and 50 deletions

View File

@@ -74,22 +74,25 @@ def load_test_file(test_file: Text) -> Dict:
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)
def load_testcase(testcase: Dict) -> TestCase:
path = testcase["config"]["path"]
try:
# validate with pydantic TestCase model
testcase_obj = TestCase.parse_obj(testcase_content)
testcase_obj = TestCase.parse_obj(testcase)
except ValidationError as ex:
err_msg = f"TestCase ValidationError:\nfile: {testcase_file}\nerror: {ex}"
err_msg = f"TestCase ValidationError:\nfile: {path}\nerror: {ex}"
logger.error(err_msg)
raise exceptions.TestCaseFormatError(err_msg)
testcase_content["config"]["path"] = testcase_file
testcase_obj.config.path = testcase_file
return testcase_obj
return testcase_content, testcase_obj
def load_testcase_file(testcase_file: Text) -> TestCase:
"""load testcase file and validate with pydantic model"""
testcase_content = load_test_file(testcase_file)
testcase_content.setdefault("config", {})["path"] = testcase_file
testcase_obj = load_testcase(testcase_content)
return testcase_obj
def load_dot_env_file(dot_env_path: Text) -> Dict: