Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 46 additions & 0 deletions testflo/duration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys
import os

class DurationSummary(object):
"""Writes a summary of the tests taking the longest time."""

def __init__(self, options, stream=sys.stdout):
self.stream = stream
self.options = options
self.startdir = os.getcwd()

def get_iter(self, input_iter):
durations = []

for test in input_iter:
durations.append((test.spec, test.end_time - test.start_time))
yield test

write = self.stream.write
mintime = self.options.durations_min

if mintime > 0.:
title = " Max duration tests with duration >= {} sec ".format(mintime)
else:
title = " Max duration tests "

prefix = "\n\n" + "=" * 30 + title + "=" * 30 + "\n\n"
suffix = "\n" + "=" * len(prefix) + "\n"

write(prefix)
count = self.options.durations

for spec, duration in sorted(durations, key=lambda t: t[1], reverse=True):
if duration < mintime:
break

if spec.startswith(self.startdir):
spec = spec[len(self.startdir):]

write("{:8.3f} sec - {}\n".format(duration, spec))

count -= 1
if count <= 0:
break

write(suffix)
7 changes: 7 additions & 0 deletions testflo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_iter(self, input_iter)
from testflo.printer import ResultPrinter
from testflo.benchmark import BenchmarkWriter
from testflo.summary import ResultSummary
from testflo.duration import DurationSummary
from testflo.discover import TestDiscoverer
from testflo.filters import TimeFilter, FailFilter

Expand Down Expand Up @@ -206,6 +207,9 @@ def func_matcher(funcname):
if options.benchmark:
pipeline.append(BenchmarkWriter(stream=bdata).get_iter)

if options.durations:
pipeline.append(DurationSummary(options).get_iter)

if options.compact:
verbose = -1
else:
Expand All @@ -217,6 +221,9 @@ def func_matcher(funcname):
])
if not options.noreport:
# print verbose results and summary to a report file
if options.durations:
pipeline.append(DurationSummary(options, stream=report).get_iter)

pipeline.extend([
ResultPrinter(options, report, verbose=1).get_iter,
ResultSummary(options, stream=report).get_iter,
Expand Down
15 changes: 12 additions & 3 deletions testflo/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def _get_parser():
metavar='FILE', default='benchmark_data.csv',
help='Name of benchmark data file. Default is benchmark_data.csv.')

parser.add_argument('--durations', action='store', type=int, dest='durations', default=0,
metavar='NUM',
help="Display 'NUM' tests with longest durations.")

parser.add_argument('--durations-min', action='store', type=float, dest='durations_min',
default=0.005, metavar='MIN_TIME',
help='Specify the minimum duration test to include in the durations list.')

parser.add_argument('--noreport', action='store_true', dest='noreport',
help="Don't create a test results file.")

Expand All @@ -116,9 +124,10 @@ def _get_parser():
parser.add_argument('--exclude', action='append', dest='excludes', metavar='GLOB', default=[],
help="Pattern to exclude test functions. Multiple patterns are allowed.")

parser.add_argument('--timeout', action='store', dest='timeout', type=float,
help='Timeout in seconds. Test will be terminated if it takes longer than timeout. Only'
' works for tests running in a subprocess (MPI and isolated).')
parser.add_argument('--timeout', action='store', dest='timeout', type=float, metavar='TIME_LIMIT',
help="Timeout in seconds. A test will be terminated if it takes longer than "
"'TIME_LIMIT'. Only works for tests running in a subprocess "
"(MPI or isolated).")

return parser

Expand Down