load_testcases_by_path: add file_type parameter

This commit is contained in:
httprunner
2017-09-19 11:34:52 +08:00
parent f19bfad128
commit 6b3da70e06

View File

@@ -88,13 +88,14 @@ def parse_function(content):
return function_meta return function_meta
def load_testcases_by_path(path): def load_testcases_by_path(path, file_type="test"):
""" load testcases from file path """ load testcases from file path
@param path @param
path could be in several type: path: path could be in several type
- absolute/relative file path - absolute/relative file path
- absolute/relative folder path - absolute/relative folder path
- list/set container with file(s) and/or folder(s) - list/set container with file(s) and/or folder(s)
file_type: "test" or "suite"
@return testcase sets list, each testset is corresponding to a file @return testcase sets list, each testset is corresponding to a file
[ [
{"name": "desc1", "config": {}, "testcases": [testcase11, testcase12]}, {"name": "desc1", "config": {}, "testcases": [testcase11, testcase12]},
@@ -105,7 +106,7 @@ def load_testcases_by_path(path):
testsets_list = [] testsets_list = []
for file_path in set(path): for file_path in set(path):
_testsets_list = load_testcases_by_path(file_path) _testsets_list = load_testcases_by_path(file_path, file_type)
testsets_list.extend(_testsets_list) testsets_list.extend(_testsets_list)
return testsets_list return testsets_list
@@ -114,8 +115,8 @@ def load_testcases_by_path(path):
path = os.path.join(os.getcwd(), path) path = os.path.join(os.getcwd(), path)
if os.path.isdir(path): if os.path.isdir(path):
files_list = utils.load_folder_files(path, file_type="test", recursive=True) files_list = utils.load_folder_files(path, file_type=file_type, recursive=True)
return load_testcases_by_path(files_list) return load_testcases_by_path(files_list, file_type)
elif os.path.isfile(path): elif os.path.isfile(path):
testset = { testset = {