Skip to content Skip to sidebar Skip to footer

Functional Test For Qmessagebox... Why Does Not Work?

I would develop some functional tests for a pyqt application that uses PyQt (or PySide) as GUI library. The tests use Unittest and Qttest library, as reported in many resources, fo

Solution 1:

The question is in general about how to test modal dialogs.

Any modal dialog including QMessageBox will not return from exec_() until it is closed, so the test code in your second code box probably never gets executed.

You could just show() it (making it non-modal) and then follow your code but don't forget to close and delete the dialog afterwards.

Or you use a Timer and schedule a click on the OK button (similar to Test modal dialog with Qt Test). Here is an example:

from PySide import QtGui, QtCore

app = QtGui.QApplication([])

box = QtGui.QMessageBox()
box.setStandardButtons(QtGui.QMessageBox.Ok)
button = box.button(QtGui.QMessageBox.Ok)
QtCore.QTimer.singleShot(0, button.clicked)
box.exec_()

Post a Comment for "Functional Test For Qmessagebox... Why Does Not Work?"