mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-13 03:39:44 +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.FUNCTIONS_MAPPING = functions
|
||||
self.init_test_variables()
|
||||
self.validation_results = []
|
||||
|
||||
def init_test_variables(self, variables_mapping=None):
|
||||
""" init test variables, called when each test(api) starts.
|
||||
@@ -167,11 +168,12 @@ class SessionContext(object):
|
||||
def validate(self, validators, resp_obj):
|
||||
""" make validations
|
||||
"""
|
||||
evaluated_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
|
||||
failures = []
|
||||
|
||||
@@ -188,10 +190,8 @@ class SessionContext(object):
|
||||
validate_pass = False
|
||||
failures.append(str(ex))
|
||||
|
||||
evaluated_validators.append(evaluated_validator)
|
||||
self.validation_results.append(evaluated_validator)
|
||||
|
||||
if not validate_pass:
|
||||
failures_string = "\n".join([failure for failure in failures])
|
||||
raise exceptions.ValidationFailure(failures_string)
|
||||
|
||||
return evaluated_validators
|
||||
|
||||
@@ -242,7 +242,7 @@ class ResponseObject(object):
|
||||
if not extractors:
|
||||
return {}
|
||||
|
||||
logger.log_info("start to extract from response object.")
|
||||
logger.log_debug("start to extract from response object.")
|
||||
extracted_variables_mapping = OrderedDict()
|
||||
extract_binds_order_dict = utils.ensure_mapping_format(extractors)
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class Runner(object):
|
||||
self.verify = config.get("verify", True)
|
||||
self.output = config.get("output", [])
|
||||
self.functions = functions
|
||||
self.evaluated_validators = []
|
||||
self.validation_results = []
|
||||
|
||||
# testcase setup hooks
|
||||
testcase_setup_hooks = config.get("setup_hooks", [])
|
||||
@@ -74,7 +74,7 @@ class Runner(object):
|
||||
if not isinstance(self.http_client_session, HttpSession):
|
||||
return
|
||||
|
||||
self.evaluated_validators = []
|
||||
self.validation_results = []
|
||||
self.http_client_session.init_meta_data()
|
||||
|
||||
def __get_test_data(self):
|
||||
@@ -84,7 +84,7 @@ class Runner(object):
|
||||
return
|
||||
|
||||
meta_data = self.http_client_session.meta_data
|
||||
meta_data["validators"] = self.evaluated_validators
|
||||
meta_data["validators"] = self.validation_results
|
||||
return meta_data
|
||||
|
||||
def _handle_skip_feature(self, test_dict):
|
||||
@@ -133,7 +133,7 @@ class Runner(object):
|
||||
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:
|
||||
|
||||
if isinstance(action, dict) and len(action) == 1:
|
||||
@@ -245,7 +245,8 @@ class Runner(object):
|
||||
# validate
|
||||
validators = test_dict.get("validate", [])
|
||||
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):
|
||||
# log request
|
||||
err_req_msg = "request: \n"
|
||||
@@ -263,21 +264,30 @@ class Runner(object):
|
||||
|
||||
raise
|
||||
|
||||
finally:
|
||||
self.validation_results = self.session_context.validation_results
|
||||
|
||||
def _run_testcase(self, testcase_dict):
|
||||
""" run single testcase.
|
||||
"""
|
||||
meta_data_list = []
|
||||
self.meta_datas = []
|
||||
config = testcase_dict.get("config", {})
|
||||
test_runner = Runner(config, self.functions, self.http_client_session)
|
||||
|
||||
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())
|
||||
return meta_data_list
|
||||
try:
|
||||
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):
|
||||
""" run single teststep of testcase.
|
||||
@@ -315,12 +325,12 @@ class Runner(object):
|
||||
self.meta_datas = None
|
||||
if "config" in test_dict:
|
||||
# nested testcase
|
||||
self.meta_datas = self._run_testcase(test_dict)
|
||||
self._run_testcase(test_dict)
|
||||
else:
|
||||
# api
|
||||
try:
|
||||
self._run_test(test_dict)
|
||||
except Exception:
|
||||
except:
|
||||
raise
|
||||
finally:
|
||||
self.meta_datas = self.__get_test_data()
|
||||
|
||||
Reference in New Issue
Block a user