Skip to content

Commit b6dce9a

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

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Jan Balster
5959
Janne Vanhala
6060
Jason R. Coombs
6161
John Towler
62+
Jon Sonesen
6263
Joshua Bronson
6364
Jurko Gospodnetić
6465
Katarzyna Jachim

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444

4545
* Updated docstrings with a more uniform style.
4646

47-
*
47+
* Add stderr write for pytest.exit(msg) during startup. Previously the message was never shown.
48+
Thanks `@BeyondEvil`_ for reporting `#1210`_. Thanks to `@JonathonSonesen`_ and
49+
`@tomviner`_ for PR.
4850

4951
* ImportErrors in plugins now are a fatal error instead of issuing a
5052
pytest warning (`#1479`_). Thanks to `@The-Compiler`_ for the PR.
@@ -58,6 +60,7 @@
5860
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503
5961
.. _#1479: https://github.com/pytest-dev/pytest/issues/1479
6062
.. _#925: https://github.com/pytest-dev/pytest/issues/925
63+
.. _#1210: https://github.com/pytest-dev/pytest/issues/1210
6164

6265
.. _@graingert: https://github.com/graingert
6366
.. _@taschini: https://github.com/taschini
@@ -67,6 +70,8 @@
6770
.. _@bagerard: https://github.com/bagerard
6871
.. _@davehunt: https://github.com/davehunt
6972
.. _@DRMacIver: https://github.com/DRMacIver
73+
.. _@BeyondEvil: https://github.com/BeyondEvil
74+
.. _@JonathonSonesen: https://github.com/JonathonSonesen
7075

7176

7277
2.9.2

_pytest/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def wrap_session(config, doit):
9292
raise
9393
except KeyboardInterrupt:
9494
excinfo = _pytest._code.ExceptionInfo()
95+
if initstate < 2 and isinstance(
96+
excinfo.value, pytest.exit.Exception):
97+
excinfo = _pytest._code.ExceptionInfo()
98+
sys.stderr.write('{0}: {1}\n'.format(
99+
type(excinfo.value).__name__, excinfo.value.msg))
95100
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
96101
session.exitstatus = EXIT_INTERRUPTED
97102
except:

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)