mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-16 11:04:08 +08:00
fix 68d2fb324c3841832267fcd7464c549748cf71c3: make variables independent on order
This commit is contained in:
@@ -24,20 +24,23 @@ class SessionContext(object):
|
||||
variables_mapping will be evaluated first.
|
||||
|
||||
Args:
|
||||
variables_mapping (dict/list)
|
||||
[
|
||||
{"TOKEN": "debugtalk"},
|
||||
{"random": "${gen_random_string(5)}"},
|
||||
{"data": '{"name": "user", "password": "123456"}'},
|
||||
{"authorization": "${gen_md5($TOKEN, $data, $random)}"}
|
||||
]
|
||||
variables_mapping (dict)
|
||||
{
|
||||
"random": "${gen_random_string(5)}",
|
||||
"authorization": "${gen_md5($TOKEN, $data, $random)}",
|
||||
"data": '{"name": "user", "password": "123456"}',
|
||||
"TOKEN": "debugtalk",
|
||||
}
|
||||
|
||||
"""
|
||||
self.test_variables_mapping = {}
|
||||
self.test_variables_mapping.update(self.session_variables_mapping)
|
||||
|
||||
variables_mapping = variables_mapping or {}
|
||||
variables_mapping = utils.ensure_mapping_format(variables_mapping)
|
||||
|
||||
self.test_variables_mapping = {}
|
||||
# priority: extracted variable > teststep variable
|
||||
self.test_variables_mapping.update(variables_mapping)
|
||||
self.test_variables_mapping.update(self.session_variables_mapping)
|
||||
|
||||
for variable_name, variable_value in variables_mapping.items():
|
||||
variable_value = self.eval_content(variable_value)
|
||||
self.update_test_variables(variable_name, variable_value)
|
||||
|
||||
@@ -767,12 +767,6 @@ def __parse_tests(tests, config, project_mapping):
|
||||
test_dict.pop("variables", {}),
|
||||
config_variables
|
||||
)
|
||||
# parse test variables with config variables
|
||||
test_dict["variables"] = parse_data(
|
||||
test_dict["variables"],
|
||||
test_dict["variables"],
|
||||
functions
|
||||
)
|
||||
|
||||
# parse test_dict name
|
||||
try:
|
||||
@@ -802,12 +796,6 @@ def __parse_tests(tests, config, project_mapping):
|
||||
test_dict.pop("variables", {}),
|
||||
config_variables
|
||||
)
|
||||
# parse test variables with config variables
|
||||
test_dict["variables"] = parse_data(
|
||||
test_dict["variables"],
|
||||
test_dict["variables"],
|
||||
functions
|
||||
)
|
||||
|
||||
# parse test_dict name
|
||||
try:
|
||||
|
||||
@@ -286,13 +286,15 @@ def ensure_mapping_format(variables):
|
||||
variables_ordered_dict = {}
|
||||
for map_dict in variables:
|
||||
variables_ordered_dict.update(map_dict)
|
||||
|
||||
return variables_ordered_dict
|
||||
|
||||
elif isinstance(variables, dict):
|
||||
variables_ordered_dict = variables
|
||||
return variables
|
||||
|
||||
else:
|
||||
raise exceptions.ParamsError("variables format error!")
|
||||
|
||||
return variables_ordered_dict
|
||||
|
||||
|
||||
def _convert_validators_to_mapping(validators):
|
||||
""" convert validators list to mapping.
|
||||
|
||||
Reference in New Issue
Block a user