From fc11b81005800fcc611edbea57c26b37561703db Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Sun, 7 Oct 2018 19:19:48 -0700 Subject: [PATCH] Exclude durations that are 0.00 seconds long. --- changelog/4063.trivial.rst | 1 + src/_pytest/runner.py | 3 +++ testing/acceptance_test.py | 32 +++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 changelog/4063.trivial.rst diff --git a/changelog/4063.trivial.rst b/changelog/4063.trivial.rst new file mode 100644 index 000000000..3e0aaf0f0 --- /dev/null +++ b/changelog/4063.trivial.rst @@ -0,0 +1 @@ +Exclude 0.00 second entries from ``--duration`` output. diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 1ba9ff310..8f1a710f9 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -30,6 +30,7 @@ def pytest_addoption(parser): def pytest_terminal_summary(terminalreporter): durations = terminalreporter.config.option.durations + verbose = terminalreporter.config.getvalue("verbose") if durations is None: return tr = terminalreporter @@ -49,6 +50,8 @@ def pytest_terminal_summary(terminalreporter): dlist = dlist[:durations] for rep in dlist: + if verbose < 2 and rep.duration < 0.01: + break nodeid = rep.nodeid.replace("::()::", "::") tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, nodeid)) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 332af27b5..9d76415da 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -816,7 +816,7 @@ class TestDurations(object): result = testdir.runpytest("--durations=10") assert result.ret == 0 result.stdout.fnmatch_lines_random( - ["*durations*", "*call*test_3*", "*call*test_2*", "*call*test_1*"] + ["*durations*", "*call*test_3*", "*call*test_2*"] ) def test_calls_show_2(self, testdir): @@ -830,6 +830,18 @@ class TestDurations(object): testdir.makepyfile(self.source) result = testdir.runpytest("--durations=0") assert result.ret == 0 + for x in "23": + for y in ("call",): # 'setup', 'call', 'teardown': + for line in result.stdout.lines: + if ("test_%s" % x) in line and y in line: + break + else: + raise AssertionError("not found {} {}".format(x, y)) + + def test_calls_showall_verbose(self, testdir): + testdir.makepyfile(self.source) + result = testdir.runpytest("--durations=0", "-vv") + assert result.ret == 0 for x in "123": for y in ("call",): # 'setup', 'call', 'teardown': for line in result.stdout.lines: @@ -840,9 +852,9 @@ class TestDurations(object): def test_with_deselected(self, testdir): testdir.makepyfile(self.source) - result = testdir.runpytest("--durations=2", "-k test_1") + result = testdir.runpytest("--durations=2", "-k test_2") assert result.ret == 0 - result.stdout.fnmatch_lines(["*durations*", "*call*test_1*"]) + result.stdout.fnmatch_lines(["*durations*", "*call*test_2*"]) def test_with_failing_collection(self, testdir): testdir.makepyfile(self.source) @@ -862,13 +874,15 @@ class TestDurations(object): class TestDurationWithFixture(object): source = """ + import pytest import time - frag = 0.001 - def setup_function(func): - time.sleep(frag * 3) - def test_1(): - time.sleep(frag*2) - def test_2(): + frag = 0.01 + + @pytest.fixture + def setup_fixt(): + time.sleep(frag) + + def test_1(setup_fixt): time.sleep(frag) """