diff --git a/doc/en/usage.rst b/doc/en/usage.rst index aafdeb55f45..509cb5a7fdd 100644 --- a/doc/en/usage.rst +++ b/doc/en/usage.rst @@ -426,14 +426,15 @@ Pytest supports the use of ``breakpoint()`` with the following behaviours: Profiling test execution duration ------------------------------------- +.. versionchanged:: 6.0 -To get a list of the slowest 10 test durations: +To get a list of the slowest 10 test durations over 1.0s long: .. code-block:: bash - pytest --durations=10 + pytest --durations=10 --durations-min=1.0 -By default, pytest will not show test durations that are too small (<0.01s) unless ``-vv`` is passed on the command-line. +By default, pytest will not show test durations that are too small (<0.005s) unless ``-vv`` is passed on the command-line. .. _faulthandler: diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 4089fc689fd..2dc940b395e 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -52,10 +52,19 @@ def pytest_addoption(parser: Parser) -> None: metavar="N", help="show N slowest setup/test durations (N=0 for all).", ) + group.addoption( + "--durations-min", + action="store", + type=float, + default=0.005, + metavar="N", + help="Minimal duration in seconds for inclusion in slowest list. Default 0.005", + ) def pytest_terminal_summary(terminalreporter: "TerminalReporter") -> None: durations = terminalreporter.config.option.durations + durations_min = terminalreporter.config.option.durations_min verbose = terminalreporter.config.getvalue("verbose") if durations is None: return @@ -76,11 +85,11 @@ def pytest_terminal_summary(terminalreporter: "TerminalReporter") -> None: dlist = dlist[:durations] for i, rep in enumerate(dlist): - if verbose < 2 and rep.duration < 0.005: + if verbose < 2 and rep.duration < durations_min: tr.write_line("") tr.write_line( - "(%s durations < 0.005s hidden. Use -vv to show these durations.)" - % (len(dlist) - i) + "(%s durations < %gs hidden. Use -vv to show these durations.)" + % (len(dlist) - i, durations_min) ) break tr.write_line("{:02.2f}s {:<8} {}".format(rep.duration, rep.when, rep.nodeid))