mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-16 12:07:36 +08:00
feat: start_at_iso_format
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user