From 46210c5a053caf852b0d5c6e562c7d760633ac31 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 23 Apr 2020 16:37:28 +0800 Subject: [PATCH] feat: start_at_iso_format --- httprunner/report/html/gen_report.py | 9 ++------- httprunner/report/summarize.py | 4 ++++ httprunner/v3/api.py | 9 ++++++++- httprunner/v3/schema.py | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/httprunner/report/html/gen_report.py b/httprunner/report/html/gen_report.py index 95772079..f76c668c 100644 --- a/httprunner/report/html/gen_report.py +++ b/httprunner/report/html/gen_report.py @@ -1,6 +1,5 @@ import io import os -from datetime import datetime from jinja2 import Template from loguru import logger @@ -19,7 +18,7 @@ def gen_html_report(testsuite_summary: TestSuiteSummary, report_template=None, r report_file (str): specify html report file path, this has higher priority than specifying report dir. """ - if not testsuite_summary.time or testsuite_summary.stat.testcases["total"] == 0: + if testsuite_summary.stat.total == 0: logger.error(f"test result testsuite_summary is empty ! {testsuite_summary}") raise SummaryEmpty @@ -34,17 +33,13 @@ def gen_html_report(testsuite_summary: TestSuiteSummary, report_template=None, r logger.info("Start to render Html report ...") - start_at_timestamp = testsuite_summary.time.start_at - utc_time_iso_8601_str = datetime.utcfromtimestamp(start_at_timestamp).isoformat() - testsuite_summary.time.start_datetime = utc_time_iso_8601_str - if report_file: report_dir = os.path.dirname(report_file) report_file_name = os.path.basename(report_file) else: report_dir = report_dir or os.path.join(os.getcwd(), "reports") # fix #826: Windows does not support file name include ":" - report_file_name = "{}.html".format(utc_time_iso_8601_str.replace(":", "").replace("-", "")) + report_file_name = "{}.html".format(testsuite_summary.time.start_at_iso_format.replace(":", "").replace("-", "")) if not os.path.isdir(report_dir): os.makedirs(report_dir) diff --git a/httprunner/report/summarize.py b/httprunner/report/summarize.py index 3234f3eb..773a9c3d 100644 --- a/httprunner/report/summarize.py +++ b/httprunner/report/summarize.py @@ -1,4 +1,5 @@ import platform +from datetime import datetime from httprunner import __version__ from httprunner.report.html.result import HtmlTestResult @@ -57,10 +58,13 @@ def get_summary(result: HtmlTestResult) -> TestCaseSummary: } """ + start_at_timestamp = result.start_at + start_at_iso_format = datetime.utcfromtimestamp(start_at_timestamp).isoformat() return TestCaseSummary( success=result.wasSuccessful(), time=TestCaseTime( start_at=result.start_at, + start_at_iso_format=start_at_iso_format, duration=result.duration ), name=result.name, diff --git a/httprunner/v3/api.py b/httprunner/v3/api.py index 8b34bfd2..bbce1a64 100644 --- a/httprunner/v3/api.py +++ b/httprunner/v3/api.py @@ -151,10 +151,17 @@ class HttpRunner(object): testsuite_summary["stat"]["fail"] += 1 testsuite_summary["success"] &= testcase_summary.success - report.aggregate_stat(testsuite_summary["time"], testcase_summary.time.dict()) testsuite_summary["details"].append(testcase_summary) + total_duration = tests_results[-1].time.start_at + tests_results[-1].time.duration \ + - tests_results[0].time.start_at + testsuite_summary["time"] = { + "start_at": tests_results[0].time.start_at, + "start_at_iso_format": tests_results[0].time.start_at_iso_format, + "duration": total_duration + } + return TestSuiteSummary.parse_obj(testsuite_summary) def run_tests(self, tests_mapping) -> TestSuiteSummary: diff --git a/httprunner/v3/schema.py b/httprunner/v3/schema.py index 11474260..fb48131c 100644 --- a/httprunner/v3/schema.py +++ b/httprunner/v3/schema.py @@ -84,8 +84,8 @@ class TestsMapping(BaseModel): class TestCaseTime(BaseModel): start_at: float + start_at_iso_format: Text duration: float - start_datetime: Text = "" class TestCaseInOut(BaseModel):