Skip to content

Commit

Permalink
fix: Total duration when running in parallel (pytest-dev#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil authored Dec 10, 2023
1 parent cd0ed43 commit e7aca52
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import math
import os
import re
import time
import warnings
from collections import defaultdict
from html import escape
Expand Down Expand Up @@ -33,6 +34,7 @@ def __init__(self, report_path, config, report_data, template, css):
self._reports = defaultdict(dict)
self._report = report_data
self._report.title = self._report_path.name
self._suite_start_time = time.time()

@property
def css(self):
Expand Down Expand Up @@ -173,7 +175,8 @@ def pytest_sessionstart(self, session):
self._report.table_header = _fix_py(headers)

self._report.running_state = "started"
self._generate_report()
if self._config.getini("generate_report_on_test"):
self._generate_report()

@pytest.hookimpl(trylast=True)
def pytest_sessionfinish(self, session):
Expand All @@ -184,6 +187,8 @@ def pytest_sessionfinish(self, session):
session=session,
)
self._report.running_state = "finished"
suite_stop_time = time.time()
self._report.total_duration = suite_stop_time - self._suite_start_time
self._generate_report()

@pytest.hookimpl(trylast=True)
Expand Down Expand Up @@ -223,8 +228,6 @@ def pytest_runtest_logreport(self, report):
else:
self._reports[report.nodeid][key] = [report]

self._report.total_duration += report.duration

finished = report.when == "teardown" and report.outcome != "rerun"
if not finished:
return
Expand Down

0 comments on commit e7aca52

Please sign in to comment.