Skip to content

Commit 919e6bd

Browse files
doomb0ttomviner
authored andcommitted
fixes pytest-dev#1210 adds stderr write for pytest.exit(msg) call
1 parent c519b95 commit 919e6bd

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@ Tom Viner
9696
Trevor Bekolay
9797
Wouter van Ackooy
9898
Bernard Pratz
99+
Jon Sonesen

CHANGELOG.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
Thanks `@bagerard`_ for reporting (`#1503`_). Thanks to `@davehunt`_ and
3737
`@tomviner`_ for PR.
3838

39+
* Add stderr write for pytest.exit(msg) calls. Previously the message was never shown.
40+
Thanks `@BeyondEvil`_ for reporting `#1210`_. Thanks to `@JonathonSonesen`_ and
41+
`@tomviner`_ for PR.
42+
3943
* Renamed the pytest ``pdb`` module (plugin) into ``debugging``.
4044

4145
*
@@ -49,8 +53,7 @@
4953
.. _#460: https://github.com/pytest-dev/pytest/pull/460
5054
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
5155
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
52-
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503
53-
.. _#1479: https://github.com/pytest-dev/pytest/issues/1479
56+
.. _#1210: https://github.com/pytest-dev/pytest/issues/1210
5457

5558
.. _@graingert: https://github.com/graingert
5659
.. _@taschini: https://github.com/taschini
@@ -59,6 +62,8 @@
5962
.. _@Vogtinator: https://github.com/Vogtinator
6063
.. _@bagerard: https://github.com/bagerard
6164
.. _@davehunt: https://github.com/davehunt
65+
.. _@BeyondEvil: https://github.com/BeyondEvil
66+
.. _@JonathonSonesen: https://github.com/JonathonSonesen
6267

6368

6469
2.9.2

_pytest/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ 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:
9494
excinfo = _pytest._code.ExceptionInfo()
9595
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
9696
session.exitstatus = EXIT_INTERRUPTED
97+
except pytest.Exit as e:
98+
sys.stderr.write('{0}: {1}\n'.format(type(e).__name__, e.msg))
9799
except:
98100
excinfo = _pytest._code.ExceptionInfo()
99101
config.notify_exception(excinfo, config.option)

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)