<div dir="ltr">Thanks I'll check it out, if anything I can use some of the techniques. But if I were to switch some tests over to pytest+qt plugin, basically the first test would create the QApplication, and once the exec is entered in first test, it never returns until the whole test suite is done? How does the test driver ever regain control to start the next test (which will presumably just create a widget and not call exec())? <div><br></div><div>With nose, we use a class that allows us to schedule "actions" (like clicking a button, verifying the state of some object, etc). A test basically schedules a bunch of actions (callbacks defined in the test) then enters a custom exec() that adds a "quit" action to exit the event loop once all actions are done, and calls the app exec(). Then control goes back to nose and the process repeats. I don't think QApplication ever gets destroyed, but its exec() is therefore called multiple times. Isn't this how QTestLib.exec() is meant to be used? </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 1, 2015 at 12:19 AM, Florian Bruhin <span dir="ltr"><<a href="mailto:me@the-compiler.org" target="_blank">me@the-compiler.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">* oliver <<a href="mailto:oliver.schoenborn@gmail.com">oliver.schoenborn@gmail.com</a>> [2015-08-31 23:38:31 -0400]:<br>
<span class="">> We have a large pyqt-based application, PyQt works awesome. We use python<br>
> nose for unit tests of business logic, and we have a set of unit tests for<br>
> the GUI components.<br>
<br>
</span>I'd recommend switching to pytest[1] with its excellent pytest-qt[2]<br>
plugin which solves those problems for you ;)<br>
<br>
It can even run nose tests, so you can gradually switch over.<br>
<br>
It also has a way[3] to wait until a signal is emitted (with a<br>
timeout) where it spins a QEventLoop.<br>
<br>
(disclaimer: I'm a contributor to both pytest and the plugin)<br>
<br>
[1] <a href="https://github.com/pytest-dev/pytest" rel="noreferrer" target="_blank">https://github.com/pytest-dev/pytest</a><br>
[2] <a href="https://github.com/pytest-dev/pytest-qt" rel="noreferrer" target="_blank">https://github.com/pytest-dev/pytest-qt</a><br>
[3] <a href="https://pytest-qt.readthedocs.org/en/1.5.1/signals.html" rel="noreferrer" target="_blank">https://pytest-qt.readthedocs.org/en/1.5.1/signals.html</a><br>
<span class=""><br>
> However, sometimes it appears that resources are not properly cleaned up<br>
> between tests: a test will crash, or will not start unless we have put a<br>
> "del some_qwidget_instance" in the teardown. Is it safe to re-use the same<br>
> QApplication instance after its exec() has returned? I.e. can we do this:<br>
><br>
> app = QApplication([])<br>
> my_gui_obj = MyGuiObj() # derives from QWidget<br>
> # other stuff<br>
> app.exec()<br>
> my_gui_obj2 = MyGuiObj() # derives from QWidget<br>
> # other stuff<br>
> app.exec()<br>
> my_gui_obj3 = MyGuiObj() # derives from QWidget<br>
> # other stuff<br>
> app.exec()<br>
><br>
> Is there anything we should do to QApplication instance between tests<br>
> (clear some caches, reset things like styles etc) so that each tests starts<br>
> with a "fresh" QApplication? What is the recommended way to test multiple<br>
> PyQt components independently of each other?<br>
<br>
</span>I don't think you should reuse a QApplication after you (I guess)<br>
called QApplication::quit.<br>
<br>
pytest-qt runs QApplication::processEvents before and after each test<br>
- it's not ideal, but it's the best we could come up with so far.<br>
<br>
Another solution might be to run a dedicated QEventLoop every time,<br>
like the waitSignal thing in [3].<br>
<span class="HOEnZb"><font color="#888888"><br>
Florian<br>
<br>
--<br>
<a href="http://www.the-compiler.org" rel="noreferrer" target="_blank">http://www.the-compiler.org</a> | <a href="mailto:me@the-compiler.org">me@the-compiler.org</a> (Mail/XMPP)<br>
GPG: 916E B0C8 FD55 A072 | <a href="http://the-compiler.org/pubkey.asc" rel="noreferrer" target="_blank">http://the-compiler.org/pubkey.asc</a><br>
I love long mails! | <a href="http://email.is-not-s.ms/" rel="noreferrer" target="_blank">http://email.is-not-s.ms/</a><br>
</font></span><br>_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><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>