Skip to content
Merged
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
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>pytest-qt</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
8 changes: 8 additions & 0 deletions .pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
1.12.dev
--------

- Exceptions caught by ``pytest-qt`` in ``sys.excepthook`` are now also printed
to ``stderr``, making debugging them easier from within an IDE.
Thanks `@fabioz`_ for the PR (`126`_)!

.. _126: https://github.com/pytest-dev/pytest-qt/pull/126

1.11.0
------

Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ Many thanks to:
.. |pycharm| image:: https://www.jetbrains.com/pycharm/docs/logo_pycharm.png
:target: https://www.jetbrains.com/pycharm

.. |pydev| image:: http://www.pydev.org/images/pydev_banner3.png
:target: https://www.pydev.org

|pycharm|

|pydev|

.. _tox: http://tox.readthedocs.org
1 change: 1 addition & 0 deletions pytestqt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def start(self):
"""
def hook(type_, value, tback):
self.exceptions.append((type_, value, tback))
sys.stderr.write(format_captured_exceptions([(type_, value, tback)]))

self.old_hook = sys.excepthook
sys.excepthook = hook
Expand Down
25 changes: 24 additions & 1 deletion tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pytestqt.exceptions import capture_exceptions, format_captured_exceptions
import pytest
import sys
from pytestqt.exceptions import format_captured_exceptions


@pytest.mark.parametrize('raise_error', [False, True])
Expand Down Expand Up @@ -244,3 +244,26 @@ def event(self, ev):
qapp.processEvents()

assert [str(e) for (t, e, tb) in exceptions] == ['mistakes were made']


def test_exceptions_to_stderr(qapp, capsys):
"""
Exceptions should still be reported to stderr.
"""
called = []
from pytestqt.qt_compat import QWidget, QEvent

class MyWidget(QWidget):

def event(self, ev):
called.append(1)
raise RuntimeError('event processed')

w = MyWidget()
with capture_exceptions() as exceptions:
qapp.postEvent(w, QEvent(QEvent.User))
qapp.processEvents()
assert called
del exceptions[:]
_out, err = capsys.readouterr()
assert "raise RuntimeError('event processed')" in err
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ passenv=DISPLAY XAUTHORITY USERNAME
basepython=python2.7
deps=pytest
sphinx
sphinx_rtd_theme
changedir=docs
setenv=
READTHEDOCS=True
Expand Down