Skip to content

pytest-qt is not printing the cause of exceptions on python 3 #215

@fabioz

Description

@fabioz

Consider the code below: The line Error 1 should appear in the stderr, but only Error 2 appears.

This happens because exceptions.format_captured_exceptions is a custom exception printer that doesn't take into account the exception cause.

from pytestqt.qt_compat import qt_api

class MyWidget(qt_api.QWidget):

    def method(self):
        raise RuntimeError('Error 1')

    def event(self, ev):
        called.append(1)
        try:
            self.method()
        finally:
            raise RuntimeError('Error 2')


weak_ref = None
called = []


def test_1(qapp):
    global weak_ref
    w = MyWidget()
    qapp.postEvent(w, qt_api.QEvent(qt_api.QEvent.User))
    qapp.processEvents()
    assert len(called) > 0
    w.deleteLater()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions