Skip to content

Commit 7356464

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

File tree

6 files changed

+28
-40
lines changed

6 files changed

+28
-40
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ Thanks for submitting a PR, your contribution is really appreciated!
22

33
Here's a quick checklist that should be present in PRs:
44

5-
- [ ] Target: for bug or doc fixes, target `master`; for new features, target `features`;
6-
- [ ] Make sure to include one or more tests for your change;
7-
- [ ] Add yourself to `AUTHORS`;
8-
- [ ] Add a new entry to `CHANGELOG.rst`
9-
* Choose any open position to avoid merge conflicts with other PRs.
10-
* Add a link to the issue you are fixing (if any) using RST syntax.
11-
* The pytest team likes to have people to acknowledged in the `CHANGELOG`, so please add a thank note to yourself ("Thanks @user for the PR") and a link to your GitHub profile. It may sound weird thanking yourself, but otherwise a maintainer would have to do it manually before or after merging instead of just using GitHub's merge button. This makes it easier on the maintainers to merge PRs.
5+
- [ ] Target: for bug or doc fixes, target `master`; for new features, target `features`
6+
- [ ] Make sure to include one or more tests for your change
7+
- [ ] Add yourself to `AUTHORS`
8+
- [ ] Add a new entry to the `CHANGELOG` (choose any open position to avoid merge conflicts with other PRs)

AUTHORS

+1
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

+6-1
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

+5
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/python/fixture.py

-32
Original file line numberDiff line numberDiff line change
@@ -336,38 +336,6 @@ def test_spam(spam):
336336
result = testdir.runpytest(testfile)
337337
result.stdout.fnmatch_lines(["*3 passed*"])
338338

339-
def test_override_autouse_fixture_with_parametrized_fixture_conftest_conftest(self, testdir):
340-
"""Test override of the autouse fixture with parametrized one on the conftest level.
341-
This test covers the issue explained in issue 1601
342-
"""
343-
testdir.makeconftest("""
344-
import pytest
345-
346-
@pytest.fixture(autouse=True)
347-
def spam():
348-
return 'spam'
349-
""")
350-
subdir = testdir.mkpydir('subdir')
351-
subdir.join("conftest.py").write(_pytest._code.Source("""
352-
import pytest
353-
354-
@pytest.fixture(params=[1, 2, 3])
355-
def spam(request):
356-
return request.param
357-
"""))
358-
testfile = subdir.join("test_spam.py")
359-
testfile.write(_pytest._code.Source("""
360-
params = {'spam': 1}
361-
362-
def test_spam(spam):
363-
assert spam == params['spam']
364-
params['spam'] += 1
365-
"""))
366-
result = testdir.runpytest()
367-
result.stdout.fnmatch_lines(["*3 passed*"])
368-
result = testdir.runpytest(testfile)
369-
result.stdout.fnmatch_lines(["*3 passed*"])
370-
371339
def test_autouse_fixture_plugin(self, testdir):
372340
# A fixture from a plugin has no baseid set, which screwed up
373341
# the autouse fixture handling.

testing/test_runner.py

+12
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)