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 authored and tomviner committed Jun 25, 2016
1 parent c519b95 commit 919e6bd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ Tom Viner
Trevor Bekolay
Wouter van Ackooy
Bernard Pratz
Jon Sonesen
9 changes: 7 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
Thanks `@bagerard`_ for reporting (`#1503`_). Thanks to `@davehunt`_ and
`@tomviner`_ for PR.

* Add stderr write for pytest.exit(msg) calls. Previously the message was never shown.
Thanks `@BeyondEvil`_ for reporting `#1210`_. Thanks to `@JonathonSonesen`_ and
`@tomviner`_ for PR.

* Renamed the pytest ``pdb`` module (plugin) into ``debugging``.

*
Expand All @@ -49,8 +53,7 @@
.. _#460: https://github.com/pytest-dev/pytest/pull/460
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503
.. _#1479: https://github.com/pytest-dev/pytest/issues/1479
.. _#1210: https://github.com/pytest-dev/pytest/issues/1210

.. _@graingert: https://github.com/graingert
.. _@taschini: https://github.com/taschini
Expand All @@ -59,6 +62,8 @@
.. _@Vogtinator: https://github.com/Vogtinator
.. _@bagerard: https://github.com/bagerard
.. _@davehunt: https://github.com/davehunt
.. _@BeyondEvil: https://github.com/BeyondEvil
.. _@JonathonSonesen: https://github.com/JonathonSonesen


2.9.2
Expand Down
4 changes: 3 additions & 1 deletion _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ def wrap_session(config, doit):
session.exitstatus = doit(config, session) or 0
except pytest.UsageError:
raise
except KeyboardInterrupt:
except KeyboardInterrupt as e:
excinfo = _pytest._code.ExceptionInfo()
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED
except pytest.Exit as e:
sys.stderr.write('{0}: {1}\n'.format(type(e).__name__, e.msg))
except:
excinfo = _pytest._code.ExceptionInfo()
config.notify_exception(excinfo, config.option)
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 919e6bd

Please sign in to comment.