mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
fix #411: validation does not display when validation failed
This commit is contained in:
@@ -18,6 +18,7 @@ class SessionContext(object):
|
|||||||
self.session_variables_mapping = utils.ensure_mapping_format(variables or {})
|
self.session_variables_mapping = utils.ensure_mapping_format(variables or {})
|
||||||
self.FUNCTIONS_MAPPING = functions
|
self.FUNCTIONS_MAPPING = functions
|
||||||
self.init_test_variables()
|
self.init_test_variables()
|
||||||
|
self.validation_results = []
|
||||||
|
|
||||||
def init_test_variables(self, variables_mapping=None):
|
def init_test_variables(self, variables_mapping=None):
|
||||||
""" init test variables, called when each test(api) starts.
|
""" init test variables, called when each test(api) starts.
|
||||||
@@ -167,11 +168,12 @@ class SessionContext(object):
|
|||||||
def validate(self, validators, resp_obj):
|
def validate(self, validators, resp_obj):
|
||||||
""" make validations
|
""" make validations
|
||||||
"""
|
"""
|
||||||
evaluated_validators = []
|
|
||||||
if not validators:
|
if not validators:
|
||||||
return evaluated_validators
|
return
|
||||||
|
|
||||||
logger.log_info("start to validate.")
|
logger.log_debug("start to validate.")
|
||||||
|
|
||||||
|
self.validation_results = []
|
||||||
validate_pass = True
|
validate_pass = True
|
||||||
failures = []
|
failures = []
|
||||||
|
|
||||||
@@ -188,10 +190,8 @@ class SessionContext(object):
|
|||||||
validate_pass = False
|
validate_pass = False
|
||||||
failures.append(str(ex))
|
failures.append(str(ex))
|
||||||
|
|
||||||
evaluated_validators.append(evaluated_validator)
|
self.validation_results.append(evaluated_validator)
|
||||||
|
|
||||||
if not validate_pass:
|
if not validate_pass:
|
||||||
failures_string = "\n".join([failure for failure in failures])
|
failures_string = "\n".join([failure for failure in failures])
|
||||||
raise exceptions.ValidationFailure(failures_string)
|
raise exceptions.ValidationFailure(failures_string)
|
||||||
|
|
||||||
return evaluated_validators
|
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ class ResponseObject(object):
|
|||||||
if not extractors:
|
if not extractors:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
logger.log_info("start to extract from response object.")
|
logger.log_debug("start to extract from response object.")
|
||||||
extracted_variables_mapping = OrderedDict()
|
extracted_variables_mapping = OrderedDict()
|
||||||
extract_binds_order_dict = utils.ensure_mapping_format(extractors)
|
extract_binds_order_dict = utils.ensure_mapping_format(extractors)
|
||||||
|
|
||||||
|
|||||||
+24
-14
@@ -51,7 +51,7 @@ class Runner(object):
|
|||||||
self.verify = config.get("verify", True)
|
self.verify = config.get("verify", True)
|
||||||
self.output = config.get("output", [])
|
self.output = config.get("output", [])
|
||||||
self.functions = functions
|
self.functions = functions
|
||||||
self.evaluated_validators = []
|
self.validation_results = []
|
||||||
|
|
||||||
# testcase setup hooks
|
# testcase setup hooks
|
||||||
testcase_setup_hooks = config.get("setup_hooks", [])
|
testcase_setup_hooks = config.get("setup_hooks", [])
|
||||||
@@ -74,7 +74,7 @@ class Runner(object):
|
|||||||
if not isinstance(self.http_client_session, HttpSession):
|
if not isinstance(self.http_client_session, HttpSession):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.evaluated_validators = []
|
self.validation_results = []
|
||||||
self.http_client_session.init_meta_data()
|
self.http_client_session.init_meta_data()
|
||||||
|
|
||||||
def __get_test_data(self):
|
def __get_test_data(self):
|
||||||
@@ -84,7 +84,7 @@ class Runner(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
meta_data = self.http_client_session.meta_data
|
meta_data = self.http_client_session.meta_data
|
||||||
meta_data["validators"] = self.evaluated_validators
|
meta_data["validators"] = self.validation_results
|
||||||
return meta_data
|
return meta_data
|
||||||
|
|
||||||
def _handle_skip_feature(self, test_dict):
|
def _handle_skip_feature(self, test_dict):
|
||||||
@@ -133,7 +133,7 @@ class Runner(object):
|
|||||||
hook_type (enum): setup/teardown
|
hook_type (enum): setup/teardown
|
||||||
|
|
||||||
"""
|
"""
|
||||||
logger.log_info("call {} hook actions.".format(hook_type))
|
logger.log_debug("call {} hook actions.".format(hook_type))
|
||||||
for action in actions:
|
for action in actions:
|
||||||
|
|
||||||
if isinstance(action, dict) and len(action) == 1:
|
if isinstance(action, dict) and len(action) == 1:
|
||||||
@@ -245,7 +245,8 @@ class Runner(object):
|
|||||||
# validate
|
# validate
|
||||||
validators = test_dict.get("validate", [])
|
validators = test_dict.get("validate", [])
|
||||||
try:
|
try:
|
||||||
self.evaluated_validators = self.session_context.validate(validators, resp_obj)
|
self.session_context.validate(validators, resp_obj)
|
||||||
|
|
||||||
except (exceptions.ParamsError, exceptions.ValidationFailure, exceptions.ExtractFailure):
|
except (exceptions.ParamsError, exceptions.ValidationFailure, exceptions.ExtractFailure):
|
||||||
# log request
|
# log request
|
||||||
err_req_msg = "request: \n"
|
err_req_msg = "request: \n"
|
||||||
@@ -263,21 +264,30 @@ class Runner(object):
|
|||||||
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
finally:
|
||||||
|
self.validation_results = self.session_context.validation_results
|
||||||
|
|
||||||
def _run_testcase(self, testcase_dict):
|
def _run_testcase(self, testcase_dict):
|
||||||
""" run single testcase.
|
""" run single testcase.
|
||||||
"""
|
"""
|
||||||
meta_data_list = []
|
self.meta_datas = []
|
||||||
config = testcase_dict.get("config", {})
|
config = testcase_dict.get("config", {})
|
||||||
test_runner = Runner(config, self.functions, self.http_client_session)
|
test_runner = Runner(config, self.functions, self.http_client_session)
|
||||||
|
|
||||||
tests = testcase_dict.get("tests", [])
|
tests = testcase_dict.get("tests", [])
|
||||||
for index, test_dict in enumerate(tests):
|
|
||||||
test_runner.run_test(test_dict)
|
|
||||||
meta_datas = test_runner.meta_datas
|
|
||||||
meta_data_list.append(meta_datas)
|
|
||||||
|
|
||||||
self.session_context.update_seesion_variables(test_runner.extract_sessions())
|
try:
|
||||||
return meta_data_list
|
for index, test_dict in enumerate(tests):
|
||||||
|
test_runner.run_test(test_dict)
|
||||||
|
_meta_datas = test_runner.meta_datas
|
||||||
|
self.meta_datas.append(_meta_datas)
|
||||||
|
|
||||||
|
self.session_context.update_seesion_variables(test_runner.extract_sessions())
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
|
meta_datas = test_runner.meta_datas
|
||||||
|
self.meta_datas.append(meta_datas)
|
||||||
|
raise exceptions.MyBaseFailure(ex)
|
||||||
|
|
||||||
def run_test(self, test_dict):
|
def run_test(self, test_dict):
|
||||||
""" run single teststep of testcase.
|
""" run single teststep of testcase.
|
||||||
@@ -315,12 +325,12 @@ class Runner(object):
|
|||||||
self.meta_datas = None
|
self.meta_datas = None
|
||||||
if "config" in test_dict:
|
if "config" in test_dict:
|
||||||
# nested testcase
|
# nested testcase
|
||||||
self.meta_datas = self._run_testcase(test_dict)
|
self._run_testcase(test_dict)
|
||||||
else:
|
else:
|
||||||
# api
|
# api
|
||||||
try:
|
try:
|
||||||
self._run_test(test_dict)
|
self._run_test(test_dict)
|
||||||
except Exception:
|
except:
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
self.meta_datas = self.__get_test_data()
|
self.meta_datas = self.__get_test_data()
|
||||||
|
|||||||
Reference in New Issue
Block a user