From 1fb20e948f2f66ec1e5ca2092a17e0379f2145c3 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 23 Apr 2020 16:48:43 +0800 Subject: [PATCH] feat: add gen_html_report method for HttpRunner class --- httprunner/cli.py | 4 +--- httprunner/v3/api.py | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/httprunner/cli.py b/httprunner/cli.py index 0c164b66..d215bc87 100644 --- a/httprunner/cli.py +++ b/httprunner/cli.py @@ -24,7 +24,6 @@ from httprunner.v3.api import HttpRunner from httprunner.ext.har2case import init_har2case_parser, main_har2case from httprunner.ext.scaffold import init_parser_scaffold, main_scaffold from httprunner.ext.locusts import init_parser_locusts, main_locusts -from httprunner.report import gen_html_report def init_parser_run(subparsers): @@ -75,8 +74,7 @@ def main_run(args): for path in args.testfile_paths: testsuite_summary = runner.run_path(path, dot_env_path=args.dot_env_path) report_dir = args.report_dir or os.path.join(os.getcwd(), "reports") - gen_html_report( - testsuite_summary, + runner.gen_html_report( report_template=args.report_template, report_dir=report_dir, report_file=args.report_file diff --git a/httprunner/v3/api.py b/httprunner/v3/api.py index bbce1a64..06c4ce61 100644 --- a/httprunner/v3/api.py +++ b/httprunner/v3/api.py @@ -6,6 +6,7 @@ from typing import List, Dict from loguru import logger from httprunner import report, loader, utils, exceptions, __version__ +from httprunner.report import gen_html_report from httprunner.v3.runner import TestCaseRunner from httprunner.v3.schema import TestsMapping, TestCaseSummary, TestSuiteSummary @@ -279,3 +280,9 @@ class HttpRunner(object): return self.run_tests(path_or_tests) else: raise exceptions.ParamsError(f"Invalid testcase path or testcases: {path_or_tests}") + + def gen_html_report(self, report_template=None, report_dir=None, report_file=None): + if not self._summary: + return None + + return gen_html_report(self._summary, report_template, report_dir, report_file)