mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 19:39:44 +08:00
change: make render_html_report separate with HttpRunner().run_tests()
This commit is contained in:
@@ -6,15 +6,12 @@ from httprunner import (__version__, exceptions, loader, logger, parser,
|
||||
|
||||
class HttpRunner(object):
|
||||
|
||||
def __init__(self, failfast=False, save_tests=False, report_template=None, report_dir=None,
|
||||
log_level="INFO", log_file=None, report_file=None):
|
||||
def __init__(self, failfast=False, save_tests=False, log_level="INFO", log_file=None):
|
||||
""" initialize HttpRunner.
|
||||
|
||||
Args:
|
||||
failfast (bool): stop the test run on the first error or failure.
|
||||
save_tests (bool): save loaded/parsed tests to JSON file.
|
||||
report_template (str): report template file path, template should be in Jinja2 format.
|
||||
report_dir (str): html report save directory.
|
||||
log_level (str): logging level.
|
||||
log_file (str): log file path.
|
||||
|
||||
@@ -29,9 +26,6 @@ class HttpRunner(object):
|
||||
self.unittest_runner = unittest.TextTestRunner(**kwargs)
|
||||
self.test_loader = unittest.TestLoader()
|
||||
self.save_tests = save_tests
|
||||
self.report_template = report_template
|
||||
self.report_dir = report_dir
|
||||
self.report_file = report_file
|
||||
self._summary = None
|
||||
|
||||
def _add_tests(self, testcases):
|
||||
@@ -201,14 +195,7 @@ class HttpRunner(object):
|
||||
if self.save_tests:
|
||||
utils.dump_logs(self._summary, project_mapping, "summary")
|
||||
|
||||
report_path = report.render_html_report(
|
||||
self._summary,
|
||||
self.report_template,
|
||||
self.report_dir,
|
||||
self.report_file
|
||||
)
|
||||
|
||||
return report_path
|
||||
return self._summary
|
||||
|
||||
def get_vars_out(self):
|
||||
""" get variables and output
|
||||
@@ -248,7 +235,7 @@ class HttpRunner(object):
|
||||
mapping (dict): if mapping is specified, it will override variables in config block.
|
||||
|
||||
Returns:
|
||||
instance: HttpRunner() instance
|
||||
dict: result summary
|
||||
|
||||
"""
|
||||
# load tests
|
||||
@@ -269,6 +256,9 @@ class HttpRunner(object):
|
||||
str: testcase/testsuite file/foler path
|
||||
dict: valid testcase/testsuite data
|
||||
|
||||
Returns:
|
||||
dict: result summary
|
||||
|
||||
"""
|
||||
logger.log_info("HttpRunner version: {}".format(__version__))
|
||||
if validator.is_testcase_path(path_or_tests):
|
||||
|
||||
@@ -5,6 +5,7 @@ from httprunner import __description__, __version__
|
||||
from httprunner.api import HttpRunner
|
||||
from httprunner.compat import is_py2
|
||||
from httprunner.logger import color_print
|
||||
from httprunner.report import render_html_report
|
||||
from httprunner.utils import (create_scaffold, get_python2_retire_msg,
|
||||
prettify_json_file)
|
||||
from httprunner.validator import validate_json_file
|
||||
@@ -83,16 +84,19 @@ def main():
|
||||
runner = HttpRunner(
|
||||
failfast=args.failfast,
|
||||
save_tests=args.save_tests,
|
||||
report_template=args.report_template,
|
||||
report_dir=args.report_dir,
|
||||
log_level=args.log_level,
|
||||
log_file=args.log_file,
|
||||
report_file=args.report_file
|
||||
log_file=args.log_file
|
||||
)
|
||||
|
||||
try:
|
||||
for path in args.testcase_paths:
|
||||
runner.run(path, dot_env_path=args.dot_env_path)
|
||||
summary = runner.run(path, dot_env_path=args.dot_env_path)
|
||||
render_html_report(
|
||||
summary,
|
||||
args.report_template,
|
||||
args.report_dir,
|
||||
args.report_file
|
||||
)
|
||||
except Exception:
|
||||
color_print("!!!!!!!!!! exception stage: {} !!!!!!!!!!".format(runner.exception_stage), "YELLOW")
|
||||
raise
|
||||
|
||||
@@ -280,7 +280,7 @@ def render_html_report(summary, report_template=None, report_dir=None, report_fi
|
||||
""" render html report with specified report name and template
|
||||
|
||||
Args:
|
||||
report_template (str): specify html report template path
|
||||
report_template (str): specify html report template path, template should be in Jinja2 format.
|
||||
report_dir (str): specify html report save directory
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user