mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-22 12:57:30 +08:00
refactor testcase config data structure
This commit is contained in:
@@ -151,13 +151,11 @@ class HttpRunner(object):
|
||||
"name": "desc1",
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional
|
||||
"request": {} # optional
|
||||
"refs": {
|
||||
"functions": {},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
}
|
||||
"request": {}, # optional
|
||||
"functions": {},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
},
|
||||
"teststeps": [
|
||||
# teststep data structure
|
||||
|
||||
@@ -867,7 +867,7 @@ def load_debugtalk_py(start_path):
|
||||
|
||||
|
||||
def load_project_tests(test_path, dot_env_path=None):
|
||||
""" load api, testcases, .env, builtin module and debugtalk.py.
|
||||
""" load api, testcases, .env, debugtalk.py functions.
|
||||
api/testcases folder is relative to project_working_directory
|
||||
|
||||
Args:
|
||||
@@ -915,13 +915,11 @@ def load_tests(path, dot_env_path=None):
|
||||
"name": "desc1",
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional
|
||||
"request": {} # optional
|
||||
"refs": {
|
||||
"functions": {},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
}
|
||||
"request": {}, # optional
|
||||
"functions": {},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
},
|
||||
"teststeps": [
|
||||
# teststep data structure
|
||||
@@ -969,7 +967,7 @@ def load_tests(path, dot_env_path=None):
|
||||
project_mapping = load_project_tests(path, dot_env_path)
|
||||
testcase = _load_testcase(raw_testcase, project_mapping)
|
||||
testcase["config"]["path"] = path
|
||||
testcase["config"]["refs"] = project_mapping
|
||||
testcase["config"].update(project_mapping)
|
||||
testcases_list = [testcase]
|
||||
except exceptions.FileFormatError:
|
||||
testcases_list = []
|
||||
|
||||
@@ -547,15 +547,10 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
"path": "testcase1_path",
|
||||
"variables": {}, # optional
|
||||
"request": {} # optional
|
||||
"refs": {
|
||||
"debugtalk": {
|
||||
"variables": {},
|
||||
"functions": {}
|
||||
},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
}
|
||||
"functions": {},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
},
|
||||
"teststeps": [
|
||||
# teststep data structure
|
||||
@@ -583,17 +578,9 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
|
||||
for testcase in testcases:
|
||||
testcase_config = testcase.setdefault("config", {})
|
||||
project_mapping = testcase_config.pop(
|
||||
"refs",
|
||||
{
|
||||
"functions": {},
|
||||
"env": {},
|
||||
"def-api": {},
|
||||
"def-testcase": {}
|
||||
}
|
||||
)
|
||||
functions = testcase_config.get("functions", {})
|
||||
|
||||
env_mapping = project_mapping["env"]
|
||||
env_mapping = testcase_config.get("env", {})
|
||||
# set OS environment variables
|
||||
utils.set_os_environ(env_mapping)
|
||||
|
||||
@@ -602,7 +589,7 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
cartesian_product_parameters_list = parse_parameters(
|
||||
config_parameters,
|
||||
testcase_config.get("variables", {}),
|
||||
project_mapping["functions"]
|
||||
functions
|
||||
) or [{}]
|
||||
|
||||
for parameter_mapping in cartesian_product_parameters_list:
|
||||
@@ -627,7 +614,7 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
parsed_value = parse_data(
|
||||
value,
|
||||
config_variables,
|
||||
project_mapping["functions"]
|
||||
functions
|
||||
)
|
||||
config_variables[key] = parsed_value
|
||||
|
||||
@@ -637,18 +624,18 @@ def parse_tests(testcases, variables_mapping=None):
|
||||
testcase_dict["config"]["name"] = parse_data(
|
||||
testcase_dict["config"].get("name", ""),
|
||||
config_variables,
|
||||
project_mapping["functions"]
|
||||
functions
|
||||
)
|
||||
|
||||
# parse config request
|
||||
testcase_dict["config"]["request"] = parse_data(
|
||||
testcase_dict["config"].get("request", {}),
|
||||
config_variables,
|
||||
project_mapping["functions"]
|
||||
functions
|
||||
)
|
||||
|
||||
# put loaded project functions to config
|
||||
testcase_dict["config"]["functions"] = project_mapping["functions"]
|
||||
testcase_dict["config"]["functions"] = functions
|
||||
parsed_testcases_list.append(testcase_dict)
|
||||
|
||||
# unset OS environment variables
|
||||
|
||||
Reference in New Issue
Block a user