Skip to content

Commit 1df2471

Browse files
ssbarneanicoddemus
andauthored
Make min duration configurable for slowest tests (#7667)
Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 54f7a87 commit 1df2471

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

changelog/7667.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
New ``--durations-min`` command-line flag controls the minimal duration for inclusion in the slowest list of tests shown by ``--durations``. Previously this was hard-coded to ``0.005s``.

doc/en/usage.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,15 @@ Pytest supports the use of ``breakpoint()`` with the following behaviours:
426426
Profiling test execution duration
427427
-------------------------------------
428428

429+
.. versionchanged:: 6.0
429430

430-
To get a list of the slowest 10 test durations:
431+
To get a list of the slowest 10 test durations over 1.0s long:
431432

432433
.. code-block:: bash
433434
434-
pytest --durations=10
435+
pytest --durations=10 --durations-min=1.0
435436
436-
By default, pytest will not show test durations that are too small (<0.01s) unless ``-vv`` is passed on the command-line.
437+
By default, pytest will not show test durations that are too small (<0.005s) unless ``-vv`` is passed on the command-line.
437438

438439

439440
.. _faulthandler:

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)