Skip to content

Commit 83aada1

Browse files
committed
fixes #1210 adds stderr write for pytest.exit(msg) call
1 parent 3d263c6 commit 83aada1

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,26 @@
3131
deprecated but still present. Thanks to `@RedBeardCode`_ and `@tomviner`_
3232
for PR (`#1626`_).
3333

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

38+
*
3639
.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
3740
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
3841
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
3942
.. _#460: https://github.com/pytest-dev/pytest/pull/460
4043
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
4144
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
45+
.. _#1210: https://github.com/pytest-dev/pytest/issues/1210
4246

4347
.. _@graingert: https://github.com/graingert
4448
.. _@taschini: https://github.com/taschini
4549
.. _@nikratio: https://github.com/nikratio
4650
.. _@RedBeardCode: https://github.com/RedBeardCode
4751
.. _@Vogtinator: https://github.com/Vogtinator
52+
.. _@BeyondEvil: https://github.com/BeyondEvil
53+
.. _@JonathonSonesen: https://github.com/JonathonSonesen
4854

4955

5056
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)