fix issue102 by introducing a --maxfailures=NUM option

also print an informative line about "stopped/interrupted" test runs
near the end.

--HG--
branch : trunk
This commit is contained in:
holger krekel
2010-05-25 16:52:09 +02:00
parent fbcf9ec543
commit c953c7d313
8 changed files with 71 additions and 19 deletions

View File

@@ -347,7 +347,7 @@ class TestCaptureFuncarg:
""")
result = testdir.runpytest(p)
result.stdout.fnmatch_lines([
"*KEYBOARD INTERRUPT*"
"*KeyboardInterrupt*"
])
assert result.ret == 2

View File

@@ -17,9 +17,10 @@ def basic_run_report(item):
return runner.call_and_report(item, "call", log=False)
class Option:
def __init__(self, verbose=False, dist=None):
def __init__(self, verbose=False, dist=None, fulltrace=False):
self.verbose = verbose
self.dist = dist
self.fulltrace = fulltrace
def _getcmdargs(self):
l = []
if self.verbose:
@@ -27,6 +28,8 @@ class Option:
if self.dist:
l.append('--dist=%s' % self.dist)
l.append('--tx=popen')
if self.fulltrace:
l.append('--fulltrace')
return l
def _getcmdstring(self):
return " ".join(self._getcmdargs())
@@ -35,6 +38,7 @@ def pytest_generate_tests(metafunc):
if "option" in metafunc.funcargnames:
metafunc.addcall(id="default", param=Option(verbose=False))
metafunc.addcall(id="verbose", param=Option(verbose=True))
metafunc.addcall(id="fulltrace", param=Option(fulltrace=True))
if not getattr(metafunc.function, 'nodist', False):
metafunc.addcall(id="verbose-dist",
param=Option(dist='each', verbose=True))
@@ -284,11 +288,28 @@ class TestTerminal:
"E assert 0",
"*_keyboard_interrupt.py:6: KeyboardInterrupt*",
])
if option.verbose:
if option.fulltrace:
result.stdout.fnmatch_lines([
"*raise KeyboardInterrupt # simulating the user*",
])
result.stdout.fnmatch_lines(['*KEYBOARD INTERRUPT*'])
result.stdout.fnmatch_lines(['*KeyboardInterrupt*'])
def test_maxfailures(self, testdir, option):
p = testdir.makepyfile("""
def test_1():
assert 0
def test_2():
assert 0
def test_3():
assert 0
""")
result = testdir.runpytest("--maxfail=2", *option._getcmdargs())
result.stdout.fnmatch_lines([
"*def test_1():*",
"*def test_2():*",
"*!! Interrupted: stopping after 2 failures*!!*",
"*2 failed*",
])
def test_pytest_report_header(self, testdir):
testdir.makeconftest("""

View File

@@ -86,6 +86,16 @@ class SessionTests:
assert failed == 1
assert passed == skipped == 0
def test_maxfail(self, testdir):
reprec = testdir.inline_runsource("""
def test_one(): assert 0
def test_two(): assert 0
def test_three(): assert 0
""", '--maxfail=2')
passed, skipped, failed = reprec.countoutcomes()
assert failed == 2
assert passed == skipped == 0
def test_broken_repr(self, testdir):
p = testdir.makepyfile("""
import py