Skip to content

Commit

Permalink
bugfix: update pytest terminal summary w/ correct timing
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyPlanden committed Jan 7, 2025
1 parent 8e43378 commit b918a36
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

import matplotlib
import plotly
import pytest
Expand Down Expand Up @@ -28,12 +30,32 @@ def pytest_addoption(parser):
parser.addoption("--docs", action="store_true", default=False, help="run doc tests")


def pytest_sessionstart(session):
start_time = time.time()
session.config.cache.set("session_start_time", start_time)


def pytest_terminal_summary(terminalreporter, exitstatus, config):
"""Add additional section to terminal summary reporting."""
total_time = sum([x.duration for x in terminalreporter.stats.get("passed", [])])
num_tests = len(terminalreporter.stats.get("passed", []))
start_time = config.cache.get("session_start_time", None)
if start_time is None:
print("Warning: Session start time not found in cache.")
return

# Collect the durations of all tests from different outcomes
total_time = 0
num_tests = 0

# Loop through all test outcomes (including skipped)
for _outcome, reports in terminalreporter.stats.items():
for report in reports:
if hasattr(report, "duration") and report.duration is not None:
total_time += report.duration
num_tests += 1

print(f"\nTotal number of tests completed: {num_tests}")
print(f"Total time taken: {total_time:.2f} seconds")
print(f"Total summed time taken: {total_time:.2f} seconds")
print(f"Total wall clock time: {(time.time() - start_time):.2f} seconds")


def pytest_configure(config):
Expand Down

0 comments on commit b918a36

Please sign in to comment.