mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-29 03:57:22 +08:00
print testcase output
This commit is contained in:
+1
-4
@@ -145,10 +145,7 @@ class HttpRunner(object):
|
|||||||
|
|
||||||
summary["success"] &= testcase_summary["success"]
|
summary["success"] &= testcase_summary["success"]
|
||||||
testcase_summary["name"] = testcase.config.get("name")
|
testcase_summary["name"] = testcase.config.get("name")
|
||||||
|
testcase_summary["in_out"] = utils.get_testcase_io(testcase)
|
||||||
in_out = utils.get_testcase_io(testcase)
|
|
||||||
utils.print_io(in_out)
|
|
||||||
testcase_summary["in_out"] = in_out
|
|
||||||
|
|
||||||
report.aggregate_stat(summary["stat"]["teststeps"], testcase_summary["stat"])
|
report.aggregate_stat(summary["stat"]["teststeps"], testcase_summary["stat"])
|
||||||
report.aggregate_stat(summary["time"], testcase_summary["time"])
|
report.aggregate_stat(summary["time"], testcase_summary["time"])
|
||||||
|
|||||||
@@ -309,7 +309,9 @@ class Runner(object):
|
|||||||
_meta_datas = test_runner.meta_datas
|
_meta_datas = test_runner.meta_datas
|
||||||
self.meta_datas.append(_meta_datas)
|
self.meta_datas.append(_meta_datas)
|
||||||
|
|
||||||
self.session_context.update_session_variables(test_runner.extract_sessions())
|
self.session_context.update_session_variables(
|
||||||
|
test_runner.extract_output(test_runner.output)
|
||||||
|
)
|
||||||
|
|
||||||
def run_test(self, test_dict):
|
def run_test(self, test_dict):
|
||||||
""" run single teststep of testcase.
|
""" run single teststep of testcase.
|
||||||
@@ -360,11 +362,6 @@ class Runner(object):
|
|||||||
finally:
|
finally:
|
||||||
self.meta_datas = self.__get_test_data()
|
self.meta_datas = self.__get_test_data()
|
||||||
|
|
||||||
def extract_sessions(self):
|
|
||||||
"""
|
|
||||||
"""
|
|
||||||
return self.extract_output(self.output)
|
|
||||||
|
|
||||||
def extract_output(self, output_variables_list):
|
def extract_output(self, output_variables_list):
|
||||||
""" extract output variables
|
""" extract output variables
|
||||||
"""
|
"""
|
||||||
@@ -381,4 +378,5 @@ class Runner(object):
|
|||||||
|
|
||||||
output[variable] = variables_mapping[variable]
|
output[variable] = variables_mapping[variable]
|
||||||
|
|
||||||
|
utils.print_info(output)
|
||||||
return output
|
return output
|
||||||
|
|||||||
+38
-51
@@ -433,13 +433,12 @@ def extend_variables(raw_variables, override_variables):
|
|||||||
|
|
||||||
|
|
||||||
def get_testcase_io(testcase):
|
def get_testcase_io(testcase):
|
||||||
""" get testcase input(variables) and output.
|
""" get and print testcase input(variables) and output.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
testcase (unittest.suite.TestSuite): corresponding to one YAML/JSON file, it has been set two attributes:
|
testcase (unittest.suite.TestSuite): corresponding to one YAML/JSON file, it has been set two attributes:
|
||||||
config: parsed config block
|
config: parsed config block
|
||||||
runner: initialized runner.Runner() with config
|
runner: initialized runner.Runner() with config
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: input(variables) and output mapping.
|
dict: input(variables) and output mapping.
|
||||||
|
|
||||||
@@ -447,73 +446,61 @@ def get_testcase_io(testcase):
|
|||||||
test_runner = testcase.runner
|
test_runner = testcase.runner
|
||||||
variables = testcase.config.get("variables", {})
|
variables = testcase.config.get("variables", {})
|
||||||
output_list = testcase.config.get("output", [])
|
output_list = testcase.config.get("output", [])
|
||||||
|
output_mapping = test_runner.extract_output(output_list)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"in": variables,
|
"in": variables,
|
||||||
"out": test_runner.extract_output(output_list)
|
"out": output_mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def print_io(in_out):
|
def print_info(info_mapping):
|
||||||
""" print input(variables) and output.
|
""" print info in mapping.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
in_out (dict): input(variables) and output mapping.
|
info_mapping (dict): input(variables) or output mapping.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> in_out = {
|
>>> info_mapping = {
|
||||||
"in": {
|
"var_a": "hello",
|
||||||
"var_a": "hello",
|
"var_b": "world"
|
||||||
"var_b": "world"
|
|
||||||
},
|
|
||||||
"out": {
|
|
||||||
"status_code": 500
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
>>> print_io(in_out)
|
>>> info_mapping = {
|
||||||
================== Variables & Output ==================
|
"status_code": 500
|
||||||
Type | Variable : Value
|
}
|
||||||
------ | ---------------- : ---------------------------
|
>>> print_info(info_mapping)
|
||||||
Var | var_a : hello
|
==================== Output ====================
|
||||||
Var | var_b : world
|
Key : Value
|
||||||
|
---------------- : ----------------------------
|
||||||
Out | status_code : 500
|
var_a : hello
|
||||||
--------------------------------------------------------
|
var_b : world
|
||||||
|
------------------------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
content_format = "{:<6} | {:<16} : {:<}\n"
|
if not info_mapping:
|
||||||
content = "\n================== Variables & Output ==================\n"
|
return
|
||||||
content += content_format.format("Type", "Variable", "Value")
|
|
||||||
content += content_format.format("-" * 6, "-" * 16, "-" * 27)
|
|
||||||
|
|
||||||
def prepare_content(var_type, in_out):
|
content_format = "{:<16} : {:<}\n"
|
||||||
content = ""
|
content = "\n==================== Output ====================\n"
|
||||||
for variable, value in in_out.items():
|
content += content_format.format("Variable", "Value")
|
||||||
if isinstance(value, (tuple, collections.deque)):
|
content += content_format.format("-" * 16, "-" * 29)
|
||||||
continue
|
|
||||||
elif isinstance(value, (dict, list)):
|
|
||||||
value = json.dumps(value)
|
|
||||||
|
|
||||||
if is_py2:
|
for key, value in info_mapping.items():
|
||||||
if isinstance(variable, unicode):
|
if isinstance(value, (tuple, collections.deque)):
|
||||||
variable = variable.encode("utf-8")
|
continue
|
||||||
if isinstance(value, unicode):
|
elif isinstance(value, (dict, list)):
|
||||||
value = value.encode("utf-8")
|
value = json.dumps(value)
|
||||||
|
|
||||||
content += content_format.format(var_type, variable, value)
|
if is_py2:
|
||||||
|
if isinstance(key, unicode):
|
||||||
|
key = key.encode("utf-8")
|
||||||
|
if isinstance(value, unicode):
|
||||||
|
value = value.encode("utf-8")
|
||||||
|
|
||||||
return content
|
content += content_format.format(key, value)
|
||||||
|
|
||||||
_in = in_out["in"]
|
content += "-" * 48 + "\n"
|
||||||
_out = in_out["out"]
|
logger.log_info(content)
|
||||||
|
|
||||||
content += prepare_content("Var", _in)
|
|
||||||
content += "\n"
|
|
||||||
content += prepare_content("Out", _out)
|
|
||||||
content += "-" * 56 + "\n"
|
|
||||||
|
|
||||||
if _out:
|
|
||||||
logger.log_info(content)
|
|
||||||
|
|
||||||
|
|
||||||
def create_scaffold(project_name):
|
def create_scaffold(project_name):
|
||||||
|
|||||||
Reference in New Issue
Block a user