Fix #1210 display msg for early calls to exit

This commit is contained in:
Tom Viner 2016-07-24 14:13:43 +02:00
parent 655df7f839
commit 42adaf5a61
4 changed files with 24 additions and 1 deletions

View File

@ -59,6 +59,7 @@ Jan Balster
Janne Vanhala Janne Vanhala
Jason R. Coombs Jason R. Coombs
John Towler John Towler
Jon Sonesen
Joshua Bronson Joshua Bronson
Jurko Gospodnetić Jurko Gospodnetić
Katarzyna Jachim Katarzyna Jachim

View File

@ -44,7 +44,9 @@
* Updated docstrings with a more uniform style. * Updated docstrings with a more uniform style.
* * Add stderr write for ``pytest.exit(msg)`` during startup. Previously the message was never shown.
Thanks `@BeyondEvil`_ for reporting `#1210`_. Thanks to `@JonathonSonesen`_ and
`@tomviner`_ for PR.
* ImportErrors in plugins now are a fatal error instead of issuing a * ImportErrors in plugins now are a fatal error instead of issuing a
pytest warning (`#1479`_). Thanks to `@The-Compiler`_ for the PR. pytest warning (`#1479`_). Thanks to `@The-Compiler`_ for the PR.
@ -58,6 +60,7 @@
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503 .. _#1503: https://github.com/pytest-dev/pytest/issues/1503
.. _#1479: https://github.com/pytest-dev/pytest/issues/1479 .. _#1479: https://github.com/pytest-dev/pytest/issues/1479
.. _#925: https://github.com/pytest-dev/pytest/issues/925 .. _#925: https://github.com/pytest-dev/pytest/issues/925
.. _#1210: https://github.com/pytest-dev/pytest/issues/1210
.. _@graingert: https://github.com/graingert .. _@graingert: https://github.com/graingert
.. _@taschini: https://github.com/taschini .. _@taschini: https://github.com/taschini
@ -67,6 +70,8 @@
.. _@bagerard: https://github.com/bagerard .. _@bagerard: https://github.com/bagerard
.. _@davehunt: https://github.com/davehunt .. _@davehunt: https://github.com/davehunt
.. _@DRMacIver: https://github.com/DRMacIver .. _@DRMacIver: https://github.com/DRMacIver
.. _@BeyondEvil: https://github.com/BeyondEvil
.. _@JonathonSonesen: https://github.com/JonathonSonesen
2.9.2 2.9.2

View File

@ -92,6 +92,11 @@ def wrap_session(config, doit):
raise raise
except KeyboardInterrupt: except KeyboardInterrupt:
excinfo = _pytest._code.ExceptionInfo() excinfo = _pytest._code.ExceptionInfo()
if initstate < 2 and isinstance(
excinfo.value, pytest.exit.Exception):
excinfo = _pytest._code.ExceptionInfo()
sys.stderr.write('{0}: {1}\n'.format(
type(excinfo.value).__name__, excinfo.value.msg))
config.hook.pytest_keyboard_interrupt(excinfo=excinfo) config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED session.exitstatus = EXIT_INTERRUPTED
except: except:

View File

@ -457,6 +457,18 @@ def test_pytest_fail():
s = excinfo.exconly(tryshort=True) s = excinfo.exconly(tryshort=True)
assert s.startswith("Failed") 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): def test_pytest_fail_notrace(testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest