fix: missing setup_hooks and teardown hooks

This commit is contained in:
debugtalk
2020-05-29 19:03:29 +08:00
parent 63f115c38e
commit f2c686dceb
3 changed files with 21 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
# FROM: examples/httpbin/hooks.yml
from httprunner import HttpRunner, TConfig, TStep
@@ -11,6 +12,7 @@ class TestCaseHooks(HttpRunner):
"setup_hooks": ["${hook_print(setup)}"],
"teardown_hooks": ["${hook_print(teardown)}"],
"path": "examples/httpbin/hooks_test.py",
"variables": {},
}
)

View File

@@ -104,7 +104,16 @@ def sort_request_by_custom_order(request: Dict) -> Dict:
def sort_step_by_custom_order(step: Dict) -> Dict:
custom_order = ["name", "variables", "request", "testcase", "extract", "validate"]
custom_order = [
"name",
"variables",
"request",
"testcase",
"setup_hooks",
"teardown_hooks",
"extract",
"validate",
]
return sort_dict_by_custom_order(step, custom_order)
@@ -116,6 +125,12 @@ def ensure_step_attachment(step: Dict) -> Dict:
if "variables" in step:
test_dict["variables"] = step["variables"]
if "setup_hooks" in step:
test_dict["setup_hooks"] = step["setup_hooks"]
if "teardown_hooks" in step:
test_dict["teardown_hooks"] = step["teardown_hooks"]
if "extract" in step:
test_dict["extract"] = convert_extractors(step["extract"])

View File

@@ -37,7 +37,7 @@ class TConfig(BaseModel):
name: Name
verify: Verify = False
base_url: BaseUrl = ""
# Text: prepare variables in debugtalk.py, ${get_variable()}
# Text: prepare variables in debugtalk.py, ${gen_variables()}
variables: Union[VariablesMapping, Text] = {}
setup_hooks: Hook = []
teardown_hooks: Hook = []
@@ -66,6 +66,8 @@ class TStep(BaseModel):
request: Request = None
testcase: Union[Text, Callable] = ""
variables: VariablesMapping = {}
setup_hooks: Hook = []
teardown_hooks: Hook = []
extract: Dict[Text, Text] = {}
validators: Validators = Field([], alias="validate")