mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
refactor HttpRunner interface
This commit is contained in:
@@ -50,14 +50,10 @@ def main_hrun():
|
|||||||
create_scaffold(project_path)
|
create_scaffold(project_path)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
kwargs = {
|
result = HttpRunner(args.testset_paths, failfast=args.failfast).run(
|
||||||
"failfast": args.failfast
|
html_report_name=args.html_report_name,
|
||||||
}
|
html_report_template=args.html_report_template
|
||||||
run_kwargs = {
|
)
|
||||||
"html_report_name": args.html_report_name,
|
|
||||||
"html_report_template": args.html_report_template
|
|
||||||
}
|
|
||||||
result = HttpRunner(args.testset_paths, **kwargs).run(**run_kwargs)
|
|
||||||
|
|
||||||
print_output(result["output"])
|
print_output(result["output"])
|
||||||
return 0 if result["success"] else 1
|
return 0 if result["success"] else 1
|
||||||
|
|||||||
@@ -131,22 +131,23 @@ class TaskSuite(unittest.TestSuite):
|
|||||||
|
|
||||||
class HttpRunner(object):
|
class HttpRunner(object):
|
||||||
|
|
||||||
def __init__(self, path, **kwargs):
|
def __init__(self, path, gen_html_report=True, **kwargs):
|
||||||
""" initialize HttpRunner with specified testset file path and test runner
|
""" initialize HttpRunner with specified testset file path and test runner
|
||||||
@params:
|
@params:
|
||||||
- path: YAML/JSON testset file path
|
- path: YAML/JSON testset file path
|
||||||
- gen_html_report: True/False
|
- gen_html_report: True/False
|
||||||
- failfast: False/True, stop the test run on the first error or failure.
|
- kwargs: key-value arguments used to initialize TextTestRunner
|
||||||
|
- failfast: False/True, stop the test run on the first error or failure.
|
||||||
"""
|
"""
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
self.gen_html_report = kwargs.pop("gen_html_report", True)
|
self.gen_html_report = gen_html_report
|
||||||
if self.gen_html_report:
|
if self.gen_html_report:
|
||||||
kwargs["resultclass"] = HtmlTestResult
|
kwargs["resultclass"] = HtmlTestResult
|
||||||
|
|
||||||
self.runner = unittest.TextTestRunner(**kwargs)
|
self.runner = unittest.TextTestRunner(**kwargs)
|
||||||
|
|
||||||
def run(self, **kwargs):
|
def run(self, mapping=None, html_report_name=None, html_report_template=None):
|
||||||
""" start to run suite
|
""" start to run suite
|
||||||
@param mapping
|
@param mapping
|
||||||
if mapping specified, it will override variables in config block
|
if mapping specified, it will override variables in config block
|
||||||
@@ -156,7 +157,7 @@ class HttpRunner(object):
|
|||||||
report template file path, template should be in Jinja2 format
|
report template file path, template should be in Jinja2 format
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
mapping = kwargs.get("mapping", {})
|
mapping = mapping or {}
|
||||||
task_suite = TaskSuite(self.path, mapping)
|
task_suite = TaskSuite(self.path, mapping)
|
||||||
except exception.TestcaseNotFound:
|
except exception.TestcaseNotFound:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -170,8 +171,8 @@ class HttpRunner(object):
|
|||||||
if self.gen_html_report:
|
if self.gen_html_report:
|
||||||
summary = result.summary
|
summary = result.summary
|
||||||
summary["report_path"] = result.render_html_report(
|
summary["report_path"] = result.render_html_report(
|
||||||
kwargs.get("html_report_name"),
|
html_report_name,
|
||||||
kwargs.get("html_report_template")
|
html_report_template
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
summary = get_summary(result)
|
summary = get_summary(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user