Skip to content

Commit 2c64ad0

Browse files
committed
fixes pytest-dev#1210 adds stderr write for pytest.exit(msg) call
1 parent 3d263c6 commit 2c64ad0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

_pytest/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def wrap_session(config, doit):
9090
session.exitstatus = doit(config, session) or 0
9191
except pytest.UsageError:
9292
raise
93-
except KeyboardInterrupt:
93+
except KeyboardInterrupt as e:
94+
sys.stderr.write('{0}: {1}\n'.format(type(e).__name__, e.msg))
9495
excinfo = _pytest._code.ExceptionInfo()
9596
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
9697
session.exitstatus = EXIT_INTERRUPTED

testing/test_runner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,18 @@ def test_pytest_fail():
457457
s = excinfo.exconly(tryshort=True)
458458
assert s.startswith("Failed")
459459

460+
def test_pytest_exit_msg(testdir):
461+
testdir.makeconftest("""
462+
import pytest
463+
464+
def pytest_configure(config):
465+
pytest.exit('oh noes')
466+
""")
467+
result = testdir.runpytest()
468+
result.stderr.fnmatch_lines([
469+
"Exit: oh noes",
470+
])
471+
460472
def test_pytest_fail_notrace(testdir):
461473
testdir.makepyfile("""
462474
import pytest

0 commit comments

Comments
 (0)