[PySide] Unit testing modal dialogs

Aaron Richiger a.richi at bluewin.ch
Sat Jun 23 20:14:20 CEST 2012


Hello Diego

I ran into the same issues some time ago and couldn't solve it... But 
now, I tried again and found a way to get references of the objects you 
mentioned. Please check the following example to see how it works:

http://pastebin.com/pL7uEXYG

It shows both, modal dialogs and message boxes. For testing, it's always 
the same approach I guess:

- Start a QTimer.singleShot() before triggering the message box or 
dialog, give it enough time to start the dialog and a callable where you 
grab the active widget
- Then trigger the message box or dialog
- The callable is executed automatically a few milliseconds later. Grab 
the active dialog and perform some actions or assert some properties on 
it as usual in tests...

I think, there is not too much overhead like this, it's just always one 
line (...singleShot...) before performing the action that executes the 
dialog.

I hope, it helps!
Have a nice evening!
Aaron

Am 22.06.2012 21:24, schrieb Diego Gaustein:
> Hello, I'm trying to write unit tests for an application I developed. 
> Using Python's unittest module and QTest helpers for simulating mouse 
> and keyboard events works fine for simple widgets, but I'm having 
> trouble testing the whole application, in particular modal dialogs, 
> since they block the flow of execution until closed.
> Using QTimers for simple dialogs works fine, but the code becomes 
> increasingly ugly for complex and nested dialogs.
> How can I test my application in a straightforward and reliable manner?
> Also, when using QMessageBox's static methods I find no way of getting 
> a reference to the newly created dialog. Is there a way around this?
>
> Many thanks,
> Diego
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120623/d3dc9497/attachment.html>


More information about the PySide mailing list