Skip to content

Commit

Permalink
fixes pytest-dev#1210 adds stderr write for pytest.exit(msg) call
Browse files Browse the repository at this point in the history
  • Loading branch information
doomb0t committed Jun 24, 2016
1 parent 3d263c6 commit 2c64ad0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def wrap_session(config, doit):
session.exitstatus = doit(config, session) or 0
except pytest.UsageError:
raise
except KeyboardInterrupt:
except KeyboardInterrupt as e:
sys.stderr.write('{0}: {1}\n'.format(type(e).__name__, e.msg))
excinfo = _pytest._code.ExceptionInfo()
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED
Expand Down
12 changes: 12 additions & 0 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ def test_pytest_fail():
s = excinfo.exconly(tryshort=True)
assert s.startswith("Failed")

def test_pytest_exit_msg(testdir):
testdir.makeconftest("""
import pytest
def pytest_configure(config):
pytest.exit('oh noes')
""")
result = testdir.runpytest()
result.stderr.fnmatch_lines([
"Exit: oh noes",
])

def test_pytest_fail_notrace(testdir):
testdir.makepyfile("""
import pytest
Expand Down

0 comments on commit 2c64ad0

Please sign in to comment.