Testing code with QNetworkAccessManager in it
-
I've got a piece of code that uses a QNetworkAccessManager. The overall software has a unit test suite, and I'm working on adding some tests for the piece of code with the QNAM in it. Run the tests from the GUI, this is no problem. But we also provide a way to run the tests from the command line, where there is no event loop. You can probably see the problem! QNAM requires an event loop to do anything.
I have never had to use a QEventLoop directly, I don't really understand how to go about it (or if it will even work for me in this case). I was hoping I could do something like:
self.blocking_event_loop = QtCore.QEventLoop() timer = QtCore.QTimer(self.blocking_event_loop) timer.setInterval(0) timer.timeout.connect(self.__event_loop_processing) timer.start() self.blocking_event_loop.exec_()Can anyone point me in the right direction?
-
Hi,
You can either use QCoreApplication or if it's just a question of having no graphic server for your tests, then you can use the offscreen qpa plugin.
And since you are using Python, did you consider using pytest-qt ? That should help you setting your tests,
-
Thanks for the input -- I was under the impression that QCoreApplication was a singleton. How can my test create and then destroy one (so it doesn't interfere with anything that any other tests might do)? I don't have any control over the test framework used, this is a tiny part of a much larger system. If it can't be tested that's not the end of the world, it's just not ideal.
-
QApplication is a singleton as well.
Would it be possible to know what is used for testing ?
And also how you are doing your GUI testing ? Because, AFAIU, that part is already covered.