add testcase loader interface

This commit is contained in:
debugtalk
2018-08-05 10:37:42 +08:00
parent 7d612bf10e
commit bf0fb675bb
5 changed files with 32 additions and 25 deletions

View File

@@ -168,7 +168,7 @@ overall_def_dict = {
testcases_cache_mapping = {}
def load_test_dependencies():
def _load_test_dependencies():
""" load all api and suite definitions.
default api folder is "$CWD/tests/api/".
default suite folder is "$CWD/tests/suite/".
@@ -177,12 +177,12 @@ def load_test_dependencies():
# load api definitions
api_def_folder = os.path.join(os.getcwd(), "tests", "api")
for test_file in load_folder_files(api_def_folder):
load_api_file(test_file)
_load_api_file(test_file)
# load suite definitions
suite_def_folder = os.path.join(os.getcwd(), "tests", "suite")
for suite_file in load_folder_files(suite_def_folder):
suite = load_test_file(suite_file)
suite = _load_test_file(suite_file)
if "def" not in suite["config"]:
raise exceptions.ParamsError("def missed in suite file: {}!".format(suite_file))
@@ -192,7 +192,7 @@ def load_test_dependencies():
overall_def_dict["suite"][function_meta["func_name"]] = suite
def load_api_file(file_path):
def _load_api_file(file_path):
""" load api definition from file and store in overall_def_dict["api"]
api file should be in format below:
[
@@ -235,7 +235,7 @@ def load_api_file(file_path):
overall_def_dict["api"][func_name] = api_dict
def load_test_file(file_path):
def _load_test_file(file_path):
""" load testcase file or testsuite file
@param file_path: absolute valid file path
file_path should be in format below:
@@ -390,7 +390,7 @@ def load_testcases(path):
elif os.path.isfile(path):
try:
testcase = load_test_file(path)
testcase = _load_test_file(path)
if testcase["testcases"]:
testcases_list = [testcase]
else:
@@ -405,3 +405,12 @@ def load_testcases(path):
testcases_cache_mapping[path] = testcases_list
return testcases_list
def load(path):
""" main interface for loading testcases
@param (str) path: testcase file/folder path
@return (list) testcases list
"""
_load_test_dependencies()
return load_testcases(path)

View File

@@ -40,9 +40,8 @@ def gen_locustfile(testcase_file_path):
"templates",
"locustfile_template"
)
loader.load_test_dependencies()
testset = loader.load_test_file(testcase_file_path)
host = testset.get("config", {}).get("request", {}).get("base_url", "")
testcases = loader.load(testcase_file_path)
host = testcases[0].get("config", {}).get("request", {}).get("base_url", "")
with io.open(template_path, encoding='utf-8') as template:
with io.open(locustfile_path, 'w', encoding='utf-8') as locustfile:

View File

@@ -178,8 +178,7 @@ def init_test_suites(path_or_testsets, mapping=None, http_client_session=None):
passed in variables mapping, it will override variables in config block
"""
if not testcase.is_testsets(path_or_testsets):
loader.load_test_dependencies()
testsets = loader.load_testcases(path_or_testsets)
testsets = loader.load(path_or_testsets)
else:
testsets = path_or_testsets