[PyQt] Testing a standalone dialog widget
antonio.valentino at tiscali.it
Mon Dec 29 20:22:43 GMT 2014
Hi Jones, hi Andre,
Il 29/12/2014 20:30, Jones, Bryan ha scritto:
> Have you read through http://johnnado.com/pyqt-qtest-example/? That shows
> testing a dialog box (no threads necessary).
the example linked by Jones terminates with a segmentation fault.
Instantiating QApplication at class level (instead of instantiating
inside the setUp method) seems to fix the issue but I'm not sure if it
I'm very interested in this topic so if anyone has some useful pointers
to material about unittesting of PyQt based GUI applications please share.
> On Sun, Dec 28, 2014 at 7:19 AM, Andre Roberge <andre.roberge at gmail.com>
>> I'm creating a series of "standalone widgets" that can be used in
>> procedural programs; the original idea is from the easygui project. To
>> give a concrete idea of their use, instead of writing:
>> ->>> name = input("What is your name? )
>> I could write
>> ->>> name = get_string("What is your name? )
>> and a dialog would pop up, inviting the user to enter the response.
>> I would like to set up some automatic testing of these widgets. I tried
>> with a third-party module
>> (pyautogui) which interacts with GUI programs, but the result is not
>> totally reliable.
>> I would prefer to use QTest but do not know how to connect with the
>> dialog; I suspect I may have
>> to use threading (as I had to do with the pyautogui solution) as the
>> dialog is effectively blocking the execution of the program.
>> Here is a simple implementation of get_string() mentioned above:
>> from PyQt4 import QtGui
>> def get_string(prompt="What is your name? ", title="Title",
>> default_response="PyQt4", app=None):
>> """GUI equivalent of input()."""
>> if app is None:
>> app = QtGui.QApplication()
>> app.dialog = QtGui.QInputDialog()
>> text, ok = app.dialog.getText(None, title, prompt,
>> if ok:
>> return text
>> if __name__ == '__main__':
>> print(get_string()) # normal blocking mode
>> app2 = QtGui.QApplication()
>> # perhaps start a delayed thread here, using QTest
>> Any help would be appreciated.
>> André Roberge
More information about the PyQt