diff --git a/py/test/outcome.py b/py/test/outcome.py index 66a6c2c95..45b5ae8b6 100644 --- a/py/test/outcome.py +++ b/py/test/outcome.py @@ -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 diff --git a/py/test/runner.py b/py/test/runner.py index e6a15e6e4..7b399e055 100644 --- a/py/test/runner.py +++ b/py/test/runner.py @@ -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): diff --git a/py/test/testing/test_outcome.py b/py/test/testing/test_outcome.py index a11691cc4..2ef2e12c2 100644 --- a/py/test/testing/test_outcome.py +++ b/py/test/testing/test_outcome.py @@ -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