* refine keyboardinterrupt handling for --dist

* generate tests for various options

--HG--
branch : 1.0.x
This commit is contained in:
holger krekel 2009-07-22 14:39:09 +02:00
parent d128854674
commit 066f8e854d
3 changed files with 40 additions and 10 deletions

View File

@ -138,6 +138,8 @@ class DSession(Session):
exitstatus = loopstate.exitstatus exitstatus = loopstate.exitstatus
break break
except KeyboardInterrupt: except KeyboardInterrupt:
excinfo = py.code.ExceptionInfo()
self.config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
exitstatus = outcome.EXIT_INTERRUPTED exitstatus = outcome.EXIT_INTERRUPTED
except: except:
self.config.pluginmanager.notify_exception() self.config.pluginmanager.notify_exception()

View File

@ -17,12 +17,16 @@ def basic_run_report(item):
return runner.call_and_report(item, "call", log=False) return runner.call_and_report(item, "call", log=False)
class Option: class Option:
def __init__(self, verbose=False): def __init__(self, verbose=False, dist=None):
self.verbose = verbose self.verbose = verbose
self.dist = dist
def _getcmdargs(self): def _getcmdargs(self):
l = [] l = []
if self.verbose: if self.verbose:
l.append('-v') l.append('-v')
if self.dist:
l.append('--dist=%s' % self.dist)
l.append('--tx=popen')
return l return l
def _getcmdstring(self): def _getcmdstring(self):
return " ".join(self._getcmdargs()) return " ".join(self._getcmdargs())
@ -37,6 +41,12 @@ def pytest_generate_tests(metafunc):
id="verbose", id="verbose",
funcargs={'option': Option(verbose=True)} funcargs={'option': Option(verbose=True)}
) )
nodist = getattr(metafunc.function, 'nodist', False)
if not nodist:
metafunc.addcall(
id="verbose-dist",
funcargs={'option': Option(dist='each', verbose=True)}
)
class TestTerminal: class TestTerminal:
def test_pass_skip_fail(self, testdir, option): def test_pass_skip_fail(self, testdir, option):
@ -49,13 +59,22 @@ class TestTerminal:
def test_func(): def test_func():
assert 0 assert 0
""") """)
result = testdir.runpytest(option._getcmdstring()) result = testdir.runpytest(*option._getcmdargs())
if option.verbose: if option.verbose:
if not option.dist:
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*test_pass_skip_fail.py:2: *test_ok*PASS*", "*test_pass_skip_fail.py:2: *test_ok*PASS*",
"*test_pass_skip_fail.py:4: *test_skip*SKIP*", "*test_pass_skip_fail.py:4: *test_skip*SKIP*",
"*test_pass_skip_fail.py:6: *test_func*FAIL*", "*test_pass_skip_fail.py:6: *test_func*FAIL*",
]) ])
else:
expected = [
"*PASS*test_pass_skip_fail.py:2: *test_ok*",
"*SKIP*test_pass_skip_fail.py:4: *test_skip*",
"*FAIL*test_pass_skip_fail.py:6: *test_func*",
]
for line in expected:
result.stdout.fnmatch_lines([line])
else: else:
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*test_pass_skip_fail.py .sF" "*test_pass_skip_fail.py .sF"
@ -68,7 +87,7 @@ class TestTerminal:
def test_collect_fail(self, testdir, option): def test_collect_fail(self, testdir, option):
p = testdir.makepyfile("import xyz") p = testdir.makepyfile("import xyz")
result = testdir.runpytest(option._getcmdstring()) result = testdir.runpytest(*option._getcmdargs())
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*test_collect_fail.py F*", "*test_collect_fail.py F*",
"> import xyz", "> import xyz",
@ -217,7 +236,15 @@ class TestTerminal:
"*FGHJ:43: custom*" "*FGHJ:43: custom*"
]) ])
def test_keyboard_interrupt_dist(self, testdir, option):
p = testdir.makepyfile("""
raise KeyboardInterrupt
""")
result = testdir.runpytest(*option._getcmdargs())
assert result.ret == 2
result.stdout.fnmatch_lines(['*KEYBOARD INTERRUPT*'])
@py.test.mark.nodist
def test_keyboard_interrupt(self, testdir, option): def test_keyboard_interrupt(self, testdir, option):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
def test_foobar(): def test_foobar():
@ -228,7 +255,7 @@ class TestTerminal:
raise KeyboardInterrupt # simulating the user raise KeyboardInterrupt # simulating the user
""") """)
result = testdir.runpytest(option._getcmdstring()) result = testdir.runpytest(*option._getcmdargs())
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
" def test_foobar():", " def test_foobar():",
"> assert 0", "> assert 0",
@ -239,6 +266,7 @@ class TestTerminal:
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*raise KeyboardInterrupt # simulating the user*", "*raise KeyboardInterrupt # simulating the user*",
]) ])
result.stdout.fnmatch_lines(['*KEYBOARD INTERRUPT*'])
def test_skip_reasons_folding(self): def test_skip_reasons_folding(self):
class longrepr: class longrepr:

View File

@ -114,7 +114,7 @@ class Session(object):
item.config.hook.pytest_runtest_protocol(item=item) item.config.hook.pytest_runtest_protocol(item=item)
except KeyboardInterrupt: except KeyboardInterrupt:
excinfo = py.code.ExceptionInfo() excinfo = py.code.ExceptionInfo()
item.config.hook.pytest_keyboard_interrupt(excinfo=excinfo) self.config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
exitstatus = outcome.EXIT_INTERRUPTED exitstatus = outcome.EXIT_INTERRUPTED
except: except:
excinfo = py.code.ExceptionInfo() excinfo = py.code.ExceptionInfo()