Skip to content

Commit b7705c7

Browse files
committed
Make min duration configurable for slowest tests
Enables users to use custom values for the threshold used to determine slow tests.
1 parent d69abff commit b7705c7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/_pytest/runner.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,19 @@ def pytest_addoption(parser: Parser) -> None:
5252
metavar="N",
5353
help="show N slowest setup/test durations (N=0 for all).",
5454
)
55+
group.addoption(
56+
"--durations-min",
57+
action="store",
58+
type=float,
59+
default=0.005,
60+
metavar="N",
61+
help="Minimal duration in seconds for inclusion in slowest list. Default 0.005",
62+
)
5563

5664

5765
def pytest_terminal_summary(terminalreporter: "TerminalReporter") -> None:
5866
durations = terminalreporter.config.option.durations
67+
durations_min = terminalreporter.config.option.durations_min
5968
verbose = terminalreporter.config.getvalue("verbose")
6069
if durations is None:
6170
return
@@ -76,11 +85,11 @@ def pytest_terminal_summary(terminalreporter: "TerminalReporter") -> None:
7685
dlist = dlist[:durations]
7786

7887
for i, rep in enumerate(dlist):
79-
if verbose < 2 and rep.duration < 0.005:
88+
if verbose < 2 and rep.duration < durations_min:
8089
tr.write_line("")
8190
tr.write_line(
82-
"(%s durations < 0.005s hidden. Use -vv to show these durations.)"
83-
% (len(dlist) - i)
91+
"(%s durations < %gs hidden. Use -vv to show these durations.)"
92+
% (len(dlist) - i, durations_min)
8493
)
8594
break
8695
tr.write_line("{:02.2f}s {:<8} {}".format(rep.duration, rep.when, rep.nodeid))

0 commit comments

Comments
 (0)