mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-25 02:10:24 +08:00
feat: implement lazy parser
This commit is contained in:
@@ -60,9 +60,16 @@ class HttpRunner(object):
|
||||
if "config" in test_dict:
|
||||
# run nested testcase
|
||||
test.__doc__ = test_dict["config"].get("name")
|
||||
variables = test_dict["config"].get("variables", {})
|
||||
else:
|
||||
# run api test
|
||||
test.__doc__ = test_dict.get("name")
|
||||
variables = test_dict.get("variables", {})
|
||||
|
||||
if isinstance(test.__doc__, parser.LazyString):
|
||||
parsed_variables = parser.parse_variables_mapping(variables, ignore=True)
|
||||
test.__doc__ = parser.parse_lazy_data(
|
||||
test.__doc__, parsed_variables)
|
||||
|
||||
return test
|
||||
|
||||
|
||||
@@ -36,16 +36,14 @@ class SessionContext(object):
|
||||
"""
|
||||
variables_mapping = variables_mapping or {}
|
||||
variables_mapping = utils.ensure_mapping_format(variables_mapping)
|
||||
variables_mapping.update(self.session_variables_mapping)
|
||||
parsed_variables_mapping = parser.parse_variables_mapping(variables_mapping)
|
||||
|
||||
self.test_variables_mapping = {}
|
||||
# priority: extracted variable > teststep variable
|
||||
self.test_variables_mapping.update(variables_mapping)
|
||||
self.test_variables_mapping.update(parsed_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)
|
||||
|
||||
def update_test_variables(self, variable_name, variable_value):
|
||||
""" update test variables, these variables are only valid in the current test.
|
||||
"""
|
||||
@@ -63,11 +61,7 @@ class SessionContext(object):
|
||||
""" evaluate content recursively, take effect on each variable and function in content.
|
||||
content may be in any data structure, include dict, list, tuple, number, string, etc.
|
||||
"""
|
||||
return parser.parse_data(
|
||||
content,
|
||||
self.test_variables_mapping,
|
||||
self.FUNCTIONS_MAPPING
|
||||
)
|
||||
return parser.parse_lazy_data(content, self.test_variables_mapping)
|
||||
|
||||
def __eval_check_item(self, validator, resp_obj):
|
||||
""" evaluate check item in validator.
|
||||
@@ -95,10 +89,8 @@ class SessionContext(object):
|
||||
# 3, dict or list, maybe containing variable/function reference, e.g. {"var": "$abc"}
|
||||
# 4, string joined by delimiter. e.g. "status_code", "headers.content-type"
|
||||
# 5, regex string, e.g. "LB[\d]*(.*)RB[\d]*"
|
||||
|
||||
if isinstance(check_item, (dict, list)) \
|
||||
or parser.extract_variables(check_item) \
|
||||
or parser.extract_functions(check_item):
|
||||
or isinstance(check_item, parser.LazyString):
|
||||
# format 1/2/3
|
||||
check_value = self.eval_content(check_item)
|
||||
else:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -199,7 +199,9 @@ class Runner(object):
|
||||
self.session_context.init_test_variables(test_variables)
|
||||
|
||||
# teststep name
|
||||
test_name = test_dict.get("name", "")
|
||||
test_name = self.session_context.eval_content(test_dict.get("name", ""))
|
||||
# TODO: refactor
|
||||
self.http_client_session.base_url = self.session_context.eval_content(test_dict.get("base_url", ""))
|
||||
|
||||
# parse test request
|
||||
raw_request = test_dict.get('request', {})
|
||||
@@ -254,7 +256,6 @@ class Runner(object):
|
||||
validators = test_dict.get("validate", [])
|
||||
try:
|
||||
self.session_context.validate(validators, resp_obj)
|
||||
|
||||
except (exceptions.ParamsError, exceptions.ValidationFailure, exceptions.ExtractFailure):
|
||||
err_msg = "{} DETAILED REQUEST & RESPONSE {}\n".format("*" * 32, "*" * 32)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user