mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-01 05:49:40 +08:00
feat: step teardown hook
This commit is contained in:
@@ -246,6 +246,17 @@ def make_teststep_chain_style(teststep: Dict) -> Text:
|
||||
call_ref_testcase = f".call({testcase})"
|
||||
step_info += call_ref_testcase
|
||||
|
||||
if "teardown_hooks" in teststep:
|
||||
teardown_hooks = teststep["teardown_hooks"]
|
||||
for hook in teardown_hooks:
|
||||
if isinstance(hook, Text):
|
||||
step_info += f'.teardown_hook("{hook}")'
|
||||
elif isinstance(hook, Dict) and len(hook) == 1:
|
||||
assign_var_name, hook_content = list(hook.items())[0]
|
||||
step_info += f'.teardown_hook("{hook}", "{assign_var_name}")'
|
||||
else:
|
||||
raise exceptions.TestCaseFormatError(f"Invalid teardown hook: {hook}")
|
||||
|
||||
if "extract" in teststep:
|
||||
# request step
|
||||
step_info += ".extract()"
|
||||
|
||||
@@ -265,8 +265,13 @@ class RequestWithOptionalArgs(object):
|
||||
self.__step_context.request.upload.update(file_info)
|
||||
return self
|
||||
|
||||
# def hooks(self):
|
||||
# pass
|
||||
def teardown_hook(self, hook: Text, assign_var_name: Text = None) -> "RequestWithOptionalArgs":
|
||||
if assign_var_name:
|
||||
self.__step_context.teardown_hooks.append({assign_var_name: hook})
|
||||
else:
|
||||
self.__step_context.teardown_hooks.append(hook)
|
||||
|
||||
return self
|
||||
|
||||
def extract(self) -> StepRequestExtraction:
|
||||
return StepRequestExtraction(self.__step_context)
|
||||
|
||||
Reference in New Issue
Block a user