add setup and teardown block, in these blocks, we can exec functions such as sleep

This commit is contained in:
debugtalk
2017-09-04 22:58:40 +08:00
parent 154e050a60
commit cd6e742808
5 changed files with 36 additions and 4 deletions

View File

@@ -79,7 +79,9 @@ class Runner(object):
"body": '{"name": "user", "password": "123456"}'
},
"extract_binds": [], # optional
"validators": [] # optional
"validators": [], # optional
"setup": [], # optional
"teardown": [] # optional
}
@return True or raise exception during test
"""
@@ -95,8 +97,16 @@ class Runner(object):
run_times = int(testcase.get("times", 1))
extract_binds = testcase.get("extract_binds", [])
validators = testcase.get("validators", [])
setup_actions = testcase.get("setup", [])
teardown_actions = testcase.get("teardown", [])
def setup_teardown(actions):
for action in actions:
self.context.exec_content_functions(action)
for _ in range(run_times):
setup_teardown(setup_actions)
resp = self.http_client_session.request(url=url, method=method, **parsed_request)
resp_obj = response.ResponseObject(resp)
@@ -105,6 +115,8 @@ class Runner(object):
resp_obj.validate(validators, self.context.get_testcase_variables_mapping())
setup_teardown(teardown_actions)
return True
def run_testset(self, testset):