Merge pull request #4086 from jeffreyrack/4063-exclude-0-durations

Exclude durations that are 0.00 seconds long.
This commit is contained in:
Bruno Oliveira 2018-10-13 22:16:04 -03:00 committed by GitHub
commit 9fb305b17b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 9 deletions

View File

@ -0,0 +1 @@
Exclude 0.00 second entries from ``--duration`` output unless ``-vv`` is passed on the command-line.

View File

@ -269,6 +269,7 @@ To get a list of the slowest 10 test durations::
pytest --durations=10 pytest --durations=10
By default, pytest will not show test durations that are too small (<0.01s) unless ``-vv`` is passed on the command-line.
Creating JUnitXML format files Creating JUnitXML format files
---------------------------------------------------- ----------------------------------------------------

View File

@ -30,6 +30,7 @@ def pytest_addoption(parser):
def pytest_terminal_summary(terminalreporter): def pytest_terminal_summary(terminalreporter):
durations = terminalreporter.config.option.durations durations = terminalreporter.config.option.durations
verbose = terminalreporter.config.getvalue("verbose")
if durations is None: if durations is None:
return return
tr = terminalreporter tr = terminalreporter
@ -49,6 +50,10 @@ def pytest_terminal_summary(terminalreporter):
dlist = dlist[:durations] dlist = dlist[:durations]
for rep in dlist: for rep in dlist:
if verbose < 2 and rep.duration < 0.005:
tr.write_line("")
tr.write_line("(0.00 durations hidden. Use -vv to show these durations.)")
break
nodeid = rep.nodeid.replace("::()::", "::") nodeid = rep.nodeid.replace("::()::", "::")
tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, nodeid)) tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, nodeid))

View File

@ -806,7 +806,11 @@ class TestDurations(object):
result = testdir.runpytest("--durations=10") result = testdir.runpytest("--durations=10")
assert result.ret == 0 assert result.ret == 0
result.stdout.fnmatch_lines_random( result.stdout.fnmatch_lines_random(
["*durations*", "*call*test_3*", "*call*test_2*", "*call*test_1*"] ["*durations*", "*call*test_3*", "*call*test_2*"]
)
assert "test_something" not in result.stdout.str()
result.stdout.fnmatch_lines(
["(0.00 durations hidden. Use -vv to show these durations.)"]
) )
def test_calls_show_2(self, testdir): def test_calls_show_2(self, testdir):
@ -820,6 +824,18 @@ class TestDurations(object):
testdir.makepyfile(self.source) testdir.makepyfile(self.source)
result = testdir.runpytest("--durations=0") result = testdir.runpytest("--durations=0")
assert result.ret == 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 x in "123":
for y in ("call",): # 'setup', 'call', 'teardown': for y in ("call",): # 'setup', 'call', 'teardown':
for line in result.stdout.lines: for line in result.stdout.lines:
@ -830,9 +846,9 @@ class TestDurations(object):
def test_with_deselected(self, testdir): def test_with_deselected(self, testdir):
testdir.makepyfile(self.source) testdir.makepyfile(self.source)
result = testdir.runpytest("--durations=2", "-k test_1") result = testdir.runpytest("--durations=2", "-k test_2")
assert result.ret == 0 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): def test_with_failing_collection(self, testdir):
testdir.makepyfile(self.source) testdir.makepyfile(self.source)
@ -852,13 +868,15 @@ class TestDurations(object):
class TestDurationWithFixture(object): class TestDurationWithFixture(object):
source = """ source = """
import pytest
import time import time
frag = 0.001 frag = 0.01
def setup_function(func):
time.sleep(frag * 3) @pytest.fixture
def test_1(): def setup_fixt():
time.sleep(frag*2) time.sleep(frag)
def test_2():
def test_1(setup_fixt):
time.sleep(frag) time.sleep(frag)
""" """