derive Exit from KeyboardInterrupt to simplify exception catching
--HG-- branch : trunk
This commit is contained in:
parent
4bc352cc7d
commit
30e04b1ec6
|
@ -36,11 +36,11 @@ class ExceptionFailure(Failed):
|
||||||
self.expr = expr
|
self.expr = expr
|
||||||
self.expected = expected
|
self.expected = expected
|
||||||
|
|
||||||
class Exit(Exception):
|
class Exit(KeyboardInterrupt):
|
||||||
""" for immediate program exits without tracebacks and reporter/summary. """
|
""" for immediate program exits without tracebacks and reporter/summary. """
|
||||||
def __init__(self, msg="unknown reason"):
|
def __init__(self, msg="unknown reason"):
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
Exception.__init__(self, msg)
|
KeyboardInterrupt.__init__(self, msg)
|
||||||
|
|
||||||
# exposed helper methods
|
# exposed helper methods
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import py
|
import py
|
||||||
|
|
||||||
from py.__.test.outcome import Exit, Skipped
|
from py.__.test.outcome import Skipped
|
||||||
|
|
||||||
def basic_run_report(item, pdb=None):
|
def basic_run_report(item, pdb=None):
|
||||||
""" return report about setting up and running a test item. """
|
""" return report about setting up and running a test item. """
|
||||||
|
@ -28,7 +28,7 @@ def basic_run_report(item, pdb=None):
|
||||||
when = "execute"
|
when = "execute"
|
||||||
finally:
|
finally:
|
||||||
outerr = capture.reset()
|
outerr = capture.reset()
|
||||||
except (Exit, KeyboardInterrupt):
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
|
@ -48,7 +48,7 @@ def basic_collect_report(collector):
|
||||||
res = collector._memocollect()
|
res = collector._memocollect()
|
||||||
finally:
|
finally:
|
||||||
outerr = capture.reset()
|
outerr = capture.reset()
|
||||||
except (Exit, KeyboardInterrupt):
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
|
@ -62,7 +62,7 @@ def forked_run_report(item, pdb=None):
|
||||||
def runforked():
|
def runforked():
|
||||||
try:
|
try:
|
||||||
testrep = basic_run_report(item)
|
testrep = basic_run_report(item)
|
||||||
except (KeyboardInterrupt, Exit):
|
except KeyboardInterrupt:
|
||||||
py.std.os._exit(EXITSTATUS_TESTEXIT)
|
py.std.os._exit(EXITSTATUS_TESTEXIT)
|
||||||
return ipickle.dumps(testrep)
|
return ipickle.dumps(testrep)
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ def forked_run_report(item, pdb=None):
|
||||||
return ipickle.loads(result.retval)
|
return ipickle.loads(result.retval)
|
||||||
else:
|
else:
|
||||||
if result.exitstatus == EXITSTATUS_TESTEXIT:
|
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)
|
return report_process_crash(item, result)
|
||||||
|
|
||||||
def report_process_crash(item, result):
|
def report_process_crash(item, result):
|
||||||
|
|
|
@ -76,6 +76,13 @@ def test_importorskip():
|
||||||
print py.code.ExceptionInfo()
|
print py.code.ExceptionInfo()
|
||||||
py.test.fail("spurious skip")
|
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():
|
def test_pytest_mark_getattr():
|
||||||
from py.__.test.outcome import mark
|
from py.__.test.outcome import mark
|
||||||
def f(): pass
|
def f(): pass
|
||||||
|
|
Loading…
Reference in New Issue