[PyKDE] Killing QApplication

Paul Waldo pwaldo at waldoware.com
Sun Apr 30 14:22:08 BST 2006


Hi all,

I'm trying to be a good boy, so I have a lot of unit tests for my python KDE 
application.  Each of the tests run fine individually, but when I run them 
all together, it seems that the application refuses to die.  The first test 
runs fine, but then subsequent tests give this message:

QApplication: There should be max one application object

Each of my unit test files subclasses this class:

#################################
class KdeTestCase(unittest.TestCase):
    """A test harness for KDE apps"""
    
    def setUp(self):
        description = "A KDE Application"
        version = "0.1";
        options = [ ("+[URL]", "Document to open", "") ]
        aboutdata = KAboutData("bobo", "KdeApp", version, description, \
            KAboutData.License_GPL, "(C) 2005 AUTHOR", None, None, 
"your at email.com")
        aboutdata.addAuthor("AUTHOR", None, "your at email.com")
        KCmdLineArgs.init(sys.argv, aboutdata)
        KCmdLineArgs.addCmdLineOptions(options)
        self.kapp = KApplication()
        self.conf = Configuration.getInstance(self.kapp)
        
    def tearDown(self):
        self.kapp.quit()
        del self.kapp   
#################################

The script to run all tests is this:
#################################
import unittest
import os
import re
import sys

def regressionTest():
    path = os.path.abspath(os.path.dirname(sys.argv[0]))
    files = os.listdir(path)
    test = re.compile("Test.+\.py$", re.IGNORECASE)
    files = filter(test.search, files)
    filenameToModuleName = lambda f: os.path.splitext(f)[0]
    moduleNames = map(filenameToModuleName, files)
    modules = map(__import__, moduleNames)
    load = unittest.defaultTestLoader.loadTestsFromModule
    return unittest.TestSuite(map(load, modules))

def main():
    loader = unittest.defaultTestLoader
    suite = regressionTest()
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite)

if __name__ == "__main__":
    main()
#################################

I've tried everything to kill the application: calling 
self.kapp.processEvents(), sleeping for a while before the next test, etc.  
When I run the script in Eric, everything works fine :-O, so I think it is a 
threading problem.  Does anyone have any suggestions?  Thanks in advance!

Paul




More information about the PyQt mailing list