Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1210 adds stderr write for pytest.exit(msg) call #1655

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ Tom Viner
Trevor Bekolay
Wouter van Ackooy
Bernard Pratz
Jon Sonesen
8 changes: 7 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,26 @@
deprecated but still present. Thanks to `@RedBeardCode`_ and `@tomviner`_
for PR (`#1626`_).

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

*
.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
.. _#460: https://github.com/pytest-dev/pytest/pull/460
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
.. _#1210: https://github.com/pytest-dev/pytest/issues/1210

.. _@graingert: https://github.com/graingert
.. _@taschini: https://github.com/taschini
.. _@nikratio: https://github.com/nikratio
.. _@RedBeardCode: https://github.com/RedBeardCode
.. _@Vogtinator: https://github.com/Vogtinator
.. _@BeyondEvil: https://github.com/BeyondEvil
.. _@JonathonSonesen: https://github.com/JonathonSonesen


2.9.2
Expand Down
4 changes: 3 additions & 1 deletion _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ def wrap_session(config, doit):
session.exitstatus = doit(config, session) or 0
except pytest.UsageError:
raise
except KeyboardInterrupt:
except KeyboardInterrupt as e:
excinfo = _pytest._code.ExceptionInfo()
Copy link
Contributor

@tomviner tomviner Jun 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few points:

  • there's no need for as e because the exception data is already in excinfo
  • I'm unsure if this is the right place to do the outputting
  • I tested pytest.exiting from a test, and it now prints the msg twice - I think investigating this and why it doesn't print when pytest.exiting from pytest_configure will point to the right place to do the outputting
  • also when the tests ran, I saw quite a few errors - these will also help point to a good solution

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thanks for bringing this up again, I think it may have to do with the init_state logic that we were talking about prior to your departure.

I will do more work on this for sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonathonSonesen cool! Ping me a message if you wanna discuss it.

config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED
except pytest.Exit as e:
sys.stderr.write('{0}: {1}\n'.format(type(e).__name__, e.msg))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the session.exitstatus when pytest.Exit is caught? It looks like it might be 0 and before this change it was EXIT_INTERNALERROR. But I might be wrong... maybe check it in the test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will have the test verify this.

except:
excinfo = _pytest._code.ExceptionInfo()
config.notify_exception(excinfo, config.option)
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