mercredi 26 août 2015

Saving Gui unit testing results in file using unittest and PyQt

I am writting functionnal tests for a PyQt based application (Ui created with Qt Designer). I followed this tutorial and everything is working fine when I simply display the tests results in the python console. The output I get from unittest when I run MargaritaMixerTest.py is:

.......
----------------------------------------------------------------------
Ran 7 tests in 0.148s

OK

The problem comes when I change the output stream to a text file by replacing the main function with:

if __name__ == "__main__":
    f = open('MargaritaMixerTest_Results.txt', 'w')
    runner = unittest.TextTestRunner(stream=f)
    unittest.main(testRunner=runner)

The only things I can see in the file are the 7 dots at the beginning, without final results. The other weird thing is when I comment 6 of the 7 tests, I get a good result in the file. The problem seems then to appear if there are more than 1 Qt window that open during the tests. I get the same bad result in my own application when I only run one test which opens more than one Qt Dialog (which are not modal in my case)

Does anyone have any ideas?

I'm using Python 2.7 with PyQt4 on Windows 7

Aucun commentaire:

Enregistrer un commentaire