Skip to content

fix: Total duration when running in parallel #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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