mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
change: --report-file, specify report file path, this has higher priority than specifying report dir.
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
# Release History
|
||||
|
||||
## 2.3.2 (2019-11-01)
|
||||
|
||||
**Changed**
|
||||
|
||||
- make render_html_report separate with HttpRunner().run_tests()
|
||||
- `--report-file`: specify report file path, this has higher priority than specifying report dir.
|
||||
|
||||
## 2.3.1 (2019-10-28)
|
||||
|
||||
**Fixed**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
__version__ = "2.3.1"
|
||||
__version__ = "2.3.2"
|
||||
__description__ = "One-stop solution for HTTP(S) testing."
|
||||
|
||||
__all__ = ["__version__", "__description__"]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from httprunner import (__version__, exceptions, loader, logger, parser,
|
||||
@@ -27,6 +28,7 @@ class HttpRunner(object):
|
||||
self.test_loader = unittest.TestLoader()
|
||||
self.save_tests = save_tests
|
||||
self._summary = None
|
||||
self.project_working_directory = None
|
||||
|
||||
def _add_tests(self, testcases):
|
||||
""" initialize testcase with Runner() and add to test suite.
|
||||
@@ -166,6 +168,8 @@ class HttpRunner(object):
|
||||
""" run testcase/testsuite data
|
||||
"""
|
||||
project_mapping = tests_mapping.get("project_mapping", {})
|
||||
self.project_working_directory = project_mapping.get("PWD", os.getcwd())
|
||||
|
||||
if self.save_tests:
|
||||
utils.dump_logs(tests_mapping, project_mapping, "loaded")
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from httprunner import __description__, __version__
|
||||
@@ -41,7 +42,7 @@ def main():
|
||||
help="specify report save directory.")
|
||||
parser.add_argument(
|
||||
'--report-file',
|
||||
help="specify report file name.")
|
||||
help="specify report file path, this has higher priority than specifying report dir.")
|
||||
parser.add_argument(
|
||||
'--failfast', action='store_true', default=False,
|
||||
help="Stop the test run on the first error or failure.")
|
||||
@@ -91,10 +92,11 @@ def main():
|
||||
try:
|
||||
for path in args.testcase_paths:
|
||||
summary = runner.run(path, dot_env_path=args.dot_env_path)
|
||||
report_dir = args.report_dir or os.path.join(runner.project_working_directory, "reports")
|
||||
render_html_report(
|
||||
summary,
|
||||
args.report_template,
|
||||
args.report_dir,
|
||||
report_dir,
|
||||
args.report_file
|
||||
)
|
||||
except Exception:
|
||||
|
||||
@@ -282,6 +282,7 @@ def render_html_report(summary, report_template=None, report_dir=None, report_fi
|
||||
Args:
|
||||
report_template (str): specify html report template path, template should be in Jinja2 format.
|
||||
report_dir (str): specify html report save directory
|
||||
report_file (str): specify html report file path, this has higher priority than specifying report dir.
|
||||
|
||||
"""
|
||||
if not report_template:
|
||||
@@ -296,18 +297,20 @@ def render_html_report(summary, report_template=None, report_dir=None, report_fi
|
||||
|
||||
logger.log_info("Start to render Html report ...")
|
||||
|
||||
report_dir = report_dir or os.path.join(os.getcwd(), "reports")
|
||||
if not os.path.isdir(report_dir):
|
||||
os.makedirs(report_dir)
|
||||
|
||||
start_at_timestamp = int(summary["time"]["start_at"])
|
||||
summary["time"]["start_datetime"] = datetime.fromtimestamp(start_at_timestamp).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
if report_file:
|
||||
report_path = os.path.join(report_dir, report_file)
|
||||
report_dir = os.path.dirname(report_file)
|
||||
report_file_name = os.path.basename(report_file)
|
||||
else:
|
||||
report_path = os.path.join(report_dir, "{}.html".format(start_at_timestamp))
|
||||
report_dir = report_dir or os.path.join(os.getcwd(), "reports")
|
||||
report_file_name = "{}.html".format(start_at_timestamp)
|
||||
|
||||
if not os.path.isdir(report_dir):
|
||||
os.makedirs(report_dir)
|
||||
|
||||
report_path = os.path.join(report_dir, report_file_name)
|
||||
with io.open(report_template, "r", encoding='utf-8') as fp_r:
|
||||
template_content = fp_r.read()
|
||||
with io.open(report_path, 'w', encoding='utf-8') as fp_w:
|
||||
|
||||
Reference in New Issue
Block a user