derive Exit from KeyboardInterrupt to simplify exception catching

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-22 13:01:48 +02:00
parent 4bc352cc7d
commit 30e04b1ec6
3 changed files with 14 additions and 7 deletions

View File

@ -36,11 +36,11 @@ class ExceptionFailure(Failed):
self.expr = expr
self.expected = expected
class Exit(Exception):
class Exit(KeyboardInterrupt):
""" for immediate program exits without tracebacks and reporter/summary. """
def __init__(self, msg="unknown reason"):
self.msg = msg
Exception.__init__(self, msg)
KeyboardInterrupt.__init__(self, msg)
# exposed helper methods

View File

@ -8,7 +8,7 @@
import py
from py.__.test.outcome import Exit, Skipped
from py.__.test.outcome import Skipped
def basic_run_report(item, pdb=None):
""" return report about setting up and running a test item. """
@ -28,7 +28,7 @@ def basic_run_report(item, pdb=None):
when = "execute"
finally:
outerr = capture.reset()
except (Exit, KeyboardInterrupt):
except KeyboardInterrupt:
raise
except:
excinfo = py.code.ExceptionInfo()
@ -48,7 +48,7 @@ def basic_collect_report(collector):
res = collector._memocollect()
finally:
outerr = capture.reset()
except (Exit, KeyboardInterrupt):
except KeyboardInterrupt:
raise
except:
excinfo = py.code.ExceptionInfo()
@ -62,7 +62,7 @@ def forked_run_report(item, pdb=None):
def runforked():
try:
testrep = basic_run_report(item)
except (KeyboardInterrupt, Exit):
except KeyboardInterrupt:
py.std.os._exit(EXITSTATUS_TESTEXIT)
return ipickle.dumps(testrep)
@ -72,7 +72,7 @@ def forked_run_report(item, pdb=None):
return ipickle.loads(result.retval)
else:
if result.exitstatus == EXITSTATUS_TESTEXIT:
raise Exit("forked test item %s raised Exit" %(item,))
py.test.exit("forked test item %s raised Exit" %(item,))
return report_process_crash(item, result)
def report_process_crash(item, result):

View File

@ -76,6 +76,13 @@ def test_importorskip():
print py.code.ExceptionInfo()
py.test.fail("spurious skip")
def test_pytest_exit():
try:
py.test.exit("hello")
except:
excinfo = py.code.ExceptionInfo()
assert excinfo.errisinstance(KeyboardInterrupt)
def test_pytest_mark_getattr():
from py.__.test.outcome import mark
def f(): pass