testing pyqt application - Qwidget: must construct a qapplication before a qwidget

前端 未结 1 403
一向
一向 2021-01-15 06:14

I have a pyqt application and like to test scripts for testing this application.

I was able to build the qapplication during my standalone testing. Not sure how to c

相关标签:
1条回答
  • 2021-01-15 06:36

    A QApplication must be created before creating any widget since it handles the eventloop

    import unittest
    import same_label
    import sys
    
    from PyQt5.QtWidgets import QApplication
    
    app = QApplication(sys.argv)
    
    
    class Test(unittest.TestCase):
        def setUp(self):
            ex = same_label.Example()
    
        def tearDown(self):
            pass
    
        def testName(self):
            pass
    
    
    if __name__ == "__main__":
        #import sys;sys.argv = ['', 'Test.testName']
        unittest.main()
    

    In the following link there is an example: http://johnnado.com/pyqt-qtest-example/, another option is to use the pytest-qt package

    0 讨论(0)
提交回复
热议问题