Skip to content

Commit 3572776

Browse files
committed
Derive outcomes.exit.Exception from SystemExit instead of KeyboardInterrupt
This is required for properly getting out of pdb, where KeyboardInterrupt is caught in py36 at least. Ref: pytest-dev#1865 (comment)
1 parent 5db46d2 commit 3572776

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/_pytest/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def wrap_session(config, doit):
205205
raise
206206
except Failed:
207207
session.exitstatus = EXIT_TESTSFAILED
208-
except KeyboardInterrupt:
208+
# except KeyboardInterrupt:
209+
except (KeyboardInterrupt, exit.Exception):
209210
excinfo = _pytest._code.ExceptionInfo.from_current()
210211
exitstatus = EXIT_INTERRUPTED
211212
if initstate <= 2 and isinstance(excinfo.value, exit.Exception):

src/_pytest/outcomes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ class Failed(OutcomeException):
4949
__module__ = "builtins"
5050

5151

52-
class Exit(KeyboardInterrupt):
52+
class Exit(SystemExit):
5353
""" raised for immediate program exits (no tracebacks/summaries)"""
5454

5555
def __init__(self, msg="unknown reason", returncode=None):
5656
self.msg = msg
5757
self.returncode = returncode
58-
KeyboardInterrupt.__init__(self, msg)
58+
SystemExit.__init__(self, msg)
5959

6060

6161
# exposed helper methods
6262

6363

6464
def exit(msg, returncode=None):
6565
"""
66-
Exit testing process as if KeyboardInterrupt was triggered.
66+
Exit testing process as if SystemExit was triggered.
6767
6868
:param str msg: message to display upon exit.
6969
:param int returncode: return code to be used when exiting pytest.

testing/test_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def test_outcomeexception_passes_except_Exception():
553553
def test_pytest_exit():
554554
with pytest.raises(pytest.exit.Exception) as excinfo:
555555
pytest.exit("hello")
556-
assert excinfo.errisinstance(KeyboardInterrupt)
556+
assert excinfo.errisinstance(pytest.exit.Exception)
557557

558558

559559
def test_pytest_fail():

0 commit comments

Comments
 (0)