<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Consolas">Hi,<br>
<br>
I have a general question about how to unit test PyQt applications
using the Python unittest moudle. I have attached a few examples.
If you have time to take a look and comment, it would be great.<br>
<br>
The first module, Foo.py, defines a simple widget called 'Widget'
which is tested in FooTest.py. FooTest.py defines an instance of a
QApplication, which is needed in order to run the test. In this
case the test runs fine.<br>
<br>
The second module, Bar.py, defines a more complex widget, also
called Widget, which starts a thread in its constructor. In real
life, this could be a used for generating an icon in the
background. This is tested in BarTest.py. In this case, the test
fails, because the unittest exits while the thread is still
running. <br>
<br>
There are ways to circumvent this, e.g:<br>
<br>
* Hook up a slot which gets called when the thread finishes<br>
* Start the event loop by calling QtGui.qApp.exec_()<br>
* Kill the event loop when the slot is called<br>
<br>
But this easily becomes messy, when you have a large and complex
code base, and I was wondering if there's some more generic
approach.<br>
<br>
I should add, that in my case I have a large nested unittest
suite, which collects all the individual unittest files. In that
case, the instance of a QApplication is only started once, by an
__init__.py file, which gets loaded once, when the entire suite it
run.<br>
<br>
All that said, if you have any comments, pointers to good
approaches, or like to share your ideas, I'd be happy to hear
them.<br>
<br>
Best regards,<br>
<br>
Mads<br>
<br>
<br>
</font><br>
<pre class="moz-signature" cols="72">--
+-----------------------------------------------------+
| Mads Ipsen |
+----------------------+------------------------------+
| Gåsebæksvej 7, 4. tv | |
| DK-2500 Valby | phone: +45-29716388 |
| Denmark | email: <a class="moz-txt-link-abbreviated" href="mailto:mads.ipsen@gmail.com">mads.ipsen@gmail.com</a> |
+----------------------+------------------------------+
</pre>
</body>
</html>