feat: cache converted pytest files, avoid duplicate making

This commit is contained in:
debugtalk
2020-05-25 18:23:54 +08:00
parent c02ab453dc
commit 1e6db89b3e

View File

@@ -15,6 +15,10 @@ from httprunner.loader import (
)
from httprunner.parser import parse_data
""" cache converted pytest files, avoid duplicate making
"""
make_files_cache_mapping: Dict[Text, List] = {}
__TMPL__ = """# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
# FROM: {{ testcase_path }}
from httprunner import HttpRunner, TConfig, TStep
@@ -203,6 +207,10 @@ def make_testsuite(testsuite: Dict) -> List[Text]:
def __make(tests_path: Text) -> List:
global make_files_cache_mapping
if tests_path in make_files_cache_mapping:
return make_files_cache_mapping[tests_path]
test_files = []
if os.path.isdir(tests_path):
files_list = load_folder_files(tests_path)
@@ -245,6 +253,8 @@ def __make(tests_path: Text) -> List:
f"test file is neither testcase nor testsuite: {test_file}"
)
make_files_cache_mapping[tests_path] = testcase_path_list
if not testcase_path_list:
logger.warning(f"No valid testcase generated on {tests_path}")
return []
@@ -253,9 +263,13 @@ def __make(tests_path: Text) -> List:
def main_make(tests_paths: List[Text]) -> List:
testcase_path_list = []
for tests_path in tests_paths:
testcase_path_list.extend(__make(tests_path))
__make(tests_path)
testcase_path_list = []
for tests_path, pytest_files in make_files_cache_mapping.items():
testcase_path_list.extend(pytest_files)
format_pytest_with_black(testcase_path_list)
return testcase_path_list