mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-16 05:09:36 +08:00
bugfix: modify request with setup_hooks
This commit is contained in:
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user