bugfix: modify request with setup_hooks

This commit is contained in:
httprunner
2018-05-14 14:29:19 +08:00
parent d2b0343266
commit ae0e6e8049
4 changed files with 51 additions and 14 deletions

View File

@@ -117,8 +117,13 @@ class Context(object):
if level == "testset":
self.testset_shared_variables_mapping[variable_name] = variable_eval_value
self.testcase_variables_mapping[variable_name] = variable_eval_value
self.testcase_parser.update_binded_variables(self.testcase_variables_mapping)
self.bind_testcase_variable(variable_name, variable_eval_value)
def bind_testcase_variable(self, variable_name, variable_value):
""" bind and update testcase variables mapping
"""
self.testcase_variables_mapping[variable_name] = variable_value
self.testcase_parser.update_binded_variables(self.testcase_variables_mapping)
def bind_extracted_variables(self, variables):
""" bind extracted variables to testset context
@@ -127,8 +132,7 @@ class Context(object):
"""
for variable_name, value in variables.items():
self.testset_shared_variables_mapping[variable_name] = value
self.testcase_variables_mapping[variable_name] = value
self.testcase_parser.update_binded_variables(self.testcase_variables_mapping)
self.bind_testcase_variable(variable_name, value)
def __update_context_functions_config(self, level, config_mapping):
"""

View File

@@ -142,7 +142,12 @@ class Runner(object):
# prepare
parsed_request = self.init_config(testcase_dict, level="testcase")
self.context.bind_variables({"request": parsed_request}, level="testcase")
self.context.bind_testcase_variable("request", parsed_request)
# setup hooks
setup_hooks = testcase_dict.get("setup_hooks", [])
setup_hooks.insert(0, "${setup_hook_prepare_kwargs($request)}")
self.do_hook_actions(setup_hooks)
try:
url = parsed_request.pop('url')
@@ -154,11 +159,6 @@ class Runner(object):
logger.log_info("{method} {url}".format(method=method, url=url))
logger.log_debug("request kwargs(raw): {kwargs}".format(kwargs=parsed_request))
# setup hooks
setup_hooks = testcase_dict.get("setup_hooks", [])
setup_hooks.insert(0, "${setup_hook_prepare_kwargs($request)}")
self.do_hook_actions(setup_hooks)
# request
resp = self.http_client_session.request(
method,
@@ -170,7 +170,7 @@ class Runner(object):
# teardown hooks
teardown_hooks = testcase_dict.get("teardown_hooks", [])
if teardown_hooks:
self.context.bind_variables({"response": resp}, level="testcase")
self.context.bind_testcase_variable("response", resp)
self.do_hook_actions(teardown_hooks)
# extract