Skip to content

Fix #1210 display msg for early calls to exit #1763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Jan Balster
Janne Vanhala
Jason R. Coombs
John Towler
Jon Sonesen
Joshua Bronson
Jurko Gospodnetić
Katarzyna Jachim
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

* 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
pytest warning (`#1479`_). Thanks to `@The-Compiler`_ for the PR.
Expand All @@ -58,6 +60,7 @@
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503
.. _#1479: https://github.com/pytest-dev/pytest/issues/1479
.. _#925: https://github.com/pytest-dev/pytest/issues/925
.. _#1210: https://github.com/pytest-dev/pytest/issues/1210

.. _@graingert: https://github.com/graingert
.. _@taschini: https://github.com/taschini
Expand All @@ -67,6 +70,8 @@
.. _@bagerard: https://github.com/bagerard
.. _@davehunt: https://github.com/davehunt
.. _@DRMacIver: https://github.com/DRMacIver
.. _@BeyondEvil: https://github.com/BeyondEvil
.. _@JonathonSonesen: https://github.com/JonathonSonesen


2.9.2
Expand Down
5 changes: 5 additions & 0 deletions _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def wrap_session(config, doit):
raise
except KeyboardInterrupt:
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)
session.exitstatus = EXIT_INTERRUPTED
except:
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