Skip to content

Commit

Permalink
fixes pytest-dev#1210 adds stderr write for pytest.exit(msg) call
Browse files Browse the repository at this point in the history
  • Loading branch information
doomb0t authored and tomviner committed Jul 24, 2016
1 parent 655df7f commit 6618b84
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 41 deletions.
11 changes: 4 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ Thanks for submitting a PR, your contribution is really appreciated!

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

- [ ] Target: for bug or doc fixes, target `master`; for new features, target `features`;
- [ ] Make sure to include one or more tests for your change;
- [ ] Add yourself to `AUTHORS`;
- [ ] Add a new entry to `CHANGELOG.rst`
* Choose any open position to avoid merge conflicts with other PRs.
* Add a link to the issue you are fixing (if any) using RST syntax.
* 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.
- [ ] Target: for bug or doc fixes, target `master`; for new features, target `features`
- [ ] Make sure to include one or more tests for your change
- [ ] Add yourself to `AUTHORS`
- [ ] Add a new entry to the `CHANGELOG` (choose any open position to avoid merge conflicts with other PRs)
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Dave Hunt
David Díaz-Barquero
David Mohr
David Vierra
Diego Russo
Edison Gustavo Muenz
Eduardo Schettino
Elizaveta Shashkova
Expand All @@ -59,6 +58,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
32 changes: 0 additions & 32 deletions testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,38 +336,6 @@ def test_spam(spam):
result = testdir.runpytest(testfile)
result.stdout.fnmatch_lines(["*3 passed*"])

def test_override_autouse_fixture_with_parametrized_fixture_conftest_conftest(self, testdir):
"""Test override of the autouse fixture with parametrized one on the conftest level.
This test covers the issue explained in issue 1601
"""
testdir.makeconftest("""
import pytest
@pytest.fixture(autouse=True)
def spam():
return 'spam'
""")
subdir = testdir.mkpydir('subdir')
subdir.join("conftest.py").write(_pytest._code.Source("""
import pytest
@pytest.fixture(params=[1, 2, 3])
def spam(request):
return request.param
"""))
testfile = subdir.join("test_spam.py")
testfile.write(_pytest._code.Source("""
params = {'spam': 1}
def test_spam(spam):
assert spam == params['spam']
params['spam'] += 1
"""))
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*3 passed*"])
result = testdir.runpytest(testfile)
result.stdout.fnmatch_lines(["*3 passed*"])

def test_autouse_fixture_plugin(self, testdir):
# A fixture from a plugin has no baseid set, which screwed up
# the autouse fixture handling.
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

0 comments on commit 6618b84

Please sign in to comment.