Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make min duration configurable for slowest tests #7667

Merged
merged 3 commits into from Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/7667.feature.rst
@@ -0,0 +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`.
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 deletions doc/en/usage.rst
Expand Up @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions src/_pytest/runner.py
Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help="Minimal duration in seconds for inclusion in slowest list. Default 0.005",
help="Minimal duration in seconds for inclusion in slowest list.",

Default is probably already appended by argparse, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not, that is why I added it explicitly. I am not sure why but I know is not printed.

)


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
Expand All @@ -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.)"
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
% (len(dlist) - i, durations_min)
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
)
break
tr.write_line("{:02.2f}s {:<8} {}".format(rep.duration, rep.when, rep.nodeid))
Expand Down