separate out the duration tests

This commit is contained in:
holger krekel 2011-11-08 18:12:16 +00:00
parent 29bf205f3a
commit a324826dfd
1 changed files with 63 additions and 49 deletions

View File

@ -465,8 +465,8 @@ class TestInvocationVariants:
"*1 failed*", "*1 failed*",
]) ])
def test_duration_test(testdir): class TestDurations:
testdir.makepyfile(""" source = """
import time import time
frag = 0.01 frag = 0.01
def test_2(): def test_2():
@ -475,39 +475,57 @@ def test_duration_test(testdir):
time.sleep(frag) time.sleep(frag)
def test_3(): def test_3():
time.sleep(frag*3) time.sleep(frag*3)
""") """
result = testdir.runpytest("--durations=10")
assert result.ret == 0
result.stdout.fnmatch_lines([
"*durations*",
"*call*test_3*",
"*call*test_2*",
"*call*test_1*",
])
assert "remaining in" not in result.stdout.str()
result = testdir.runpytest("--durations=2") def test_calls(self, testdir):
assert result.ret == 0 testdir.makepyfile(self.source)
result.stdout.fnmatch_lines([ result = testdir.runpytest("--durations=10")
"*durations*", assert result.ret == 0
"*call*test_3*", result.stdout.fnmatch_lines([
"*call*test_2*", "*durations*",
"*s*%*remaining in 7 test phases", "*call*test_3*",
]) "*call*test_2*",
assert "test_1" not in result.stdout.str() "*call*test_1*",
result = testdir.runpytest("--durations=0") ])
assert result.ret == 0 assert "remaining in" not in result.stdout.str()
for x in "123":
for y in 'call',: #'setup', 'call', 'teardown':
l = []
for line in result.stdout.lines:
if ("test_%s" % x) in line and y in line:
break
else:
raise AssertionError("not found %s %s" % (x,y))
def test_duration_test_with_fixture(testdir): def test_calls_show_2(self, testdir):
testdir.makepyfile(""" testdir.makepyfile(self.source)
result = testdir.runpytest("--durations=2")
assert result.ret == 0
result.stdout.fnmatch_lines([
"*durations*",
"*call*test_3*",
"*call*test_2*",
"*s*%*remaining in 7 test phases",
])
assert "test_1" not in result.stdout.str()
def test_calls_showall(self, testdir):
testdir.makepyfile(self.source)
result = testdir.runpytest("--durations=0")
assert result.ret == 0
for x in "123":
for y in 'call',: #'setup', 'call', 'teardown':
l = []
for line in result.stdout.lines:
if ("test_%s" % x) in line and y in line:
break
else:
raise AssertionError("not found %s %s" % (x,y))
def test_with_deselected(self, testdir):
testdir.makepyfile(self.source)
result = testdir.runpytest("--durations=2", "-k test_1")
assert result.ret == 0
result.stdout.fnmatch_lines([
"*durations*",
"*call*test_1*",
])
class TestDurationWithFixture:
source = """
import time import time
frag = 0.01 frag = 0.01
def setup_function(func): def setup_function(func):
@ -517,21 +535,17 @@ def test_duration_test_with_fixture(testdir):
time.sleep(frag*2) time.sleep(frag*2)
def test_2(): def test_2():
time.sleep(frag) time.sleep(frag)
""") """
result = testdir.runpytest("--durations=10") def test_setup_function(self, testdir):
assert result.ret == 0 testdir.makepyfile(self.source)
result.stdout.fnmatch_lines([ result = testdir.runpytest("--durations=10")
"*durations*", assert result.ret == 0
"*setup*test_1*",
"*setup*test_2*",
"*call*test_1*",
"*call*test_2*",
])
result = testdir.runpytest("--durations=2", "-k test_1") result.stdout.fnmatch_lines([
assert result.ret == 0 "*durations*",
result.stdout.fnmatch_lines([ "*setup*test_1*",
"*durations*", "*setup*test_2*",
"*call*test_1*", "*call*test_1*",
]) "*call*test_2*",
])