<div dir="ltr">We have a large pyqt-based application, PyQt works awesome. We use python nose for unit tests of business logic, and we have a set of unit tests for the GUI components. <div><br></div><div>For these, each test class's setup() instantiates QApplication if QApplication.instance() is None, starts a second QThread (needed by the application), intantiates the GUI component to be tested in main thread, connects GUI component to objects that get modified by the second thread, queues some functions that will get fired some seconds in the future (via QTimer) to simulate user actions, then enters the event loop via QApplication's exec(). The functions call methods on the GUI component and assert its resulting state is as expected. This works well, Qt is amazing for its ability to generate events and pretend user actions. </div><div><br></div><div>However, sometimes it appears that resources are not properly cleaned up between tests: a test will crash, or will not start unless we have put a "del some_qwidget_instance" in the teardown. Is it safe to re-use the same QApplication instance after its exec() has returned? I.e. can we do this:</div><div><br></div><div>app = QApplication([])</div><div>my_gui_obj = MyGuiObj()  # derives from QWidget</div><div># other stuff</div><div>app.exec()<br clear="all"><div><div>my_gui_obj2 = MyGuiObj()  # derives from QWidget</div><div># other stuff</div><div>app.exec()<br clear="all"></div></div><div><div>my_gui_obj3 = MyGuiObj()  # derives from QWidget</div><div># other stuff</div><div>app.exec()<br clear="all"></div></div><div><br></div><div>Is there anything we should do to QApplication instance between tests (clear some caches, reset things like styles etc) so that each tests starts with a "fresh" QApplication? What is the recommended way to test multiple PyQt components independently of each other? </div><div><br></div><div>-- </div><div class="gmail_signature"><div dir="ltr"><font size="2">Oliver</font><div><font size="1">Author of these Open Source: <a href="http://pubsub.sf.net" target="_blank">PyPubSub</a>, L<a href="http://lua-icxx.sf.net" target="_blank">ua-iCxx</a>, <a href="http://iof.sf.net" target="_blank">iof</a></font></div><div><font size="1">Regular contributor on <a href="http://stackoverflow.com/users/869951/schollii" target="_blank">StackOverflow</a></font></div><div><br></div><div></div></div></div>
</div></div>