I\'m building a PySide 1.1.0-based application, and have been looking for good examples to look at for unit and functional testing my application. I want to be able to do f
In my case, I was getting an error 'QPixmap: Must construct a QApplication before a QPaintDevice'.
If you need to have a QApplication instance for your tests (eg use QPixmap), here's one way to do it. Just create a singleton so that you are ensured one and only one QApplication instance.
This is buried as a helper for tests in the PySide source.
import unittest
from PySide.QtGui import QApplication
_instance = None
class UsesQApplication(unittest.TestCase):
'''Helper class to provide QApplication instances'''
qapplication = True
def setUp(self):
'''Creates the QApplication instance'''
# Simple way of making instance a singleton
super(UsesQApplication, self).setUp()
global _instance
if _instance is None:
_instance = QApplication([])
self.app = _instance
def tearDown(self):
'''Deletes the reference owned by self'''
del self.app
super(UsesQApplication, self).tearDown()
and then subclass UsesQApplication
from PySide import QtGui
class Test(UsesQApplication):
def setUp(self):
#If you override setup, tearDown, make sure
#to have a super call
super(TestFilterListItem, self).setUp()
def tearDown(self):
super(TestFilterListItem, self).tearDown()
def testName(self):
pix = QtGui.QPixmap(20,20)
self.assertTrue(True)
hope this helps