views:

82

answers:

3

Hello,

I have a test suite and I am trying to get it to work with the tests I have created. The test work if I run them individually but I want to run them all in a test suite. The code below show the test suite created:

import unittest

def suite():
    modules_to_test = ('TestAbsoluteMove', 'TestContinuousMove') # and so on
    alltests = unittest.TestSuite()
    for module in map(__import__, modules_to_test):
        alltests.addTest(unittest.findTestCases(module))
    return alltests

if __name__ == '__main__':
    unittest.main(defaultTest='suite')

I have placed this code into my test code to link up with the suite:

class AbsoluteMoveTestSuite(unittest.TestSuite):

def makeAbsoluteMoveTestSuite():
    suite = unittest.TestSuite()
    suite.addTest(TestAbsoluteMove("BasicAbsolutePan"))
    suite.addTest(TestAbsoluteMove("VerifyAbsolutePan"))
    suite.addTest(TestAbsoluteMove("VerifyAbsoluteTilt"))
    suite.addTest(TestAbsoluteMove("VerifyAbsolutePanSpeed"))
    suite.addTest(TestAbsoluteMove("VerifyAbsoluteTiltSpeed"))
    return suite

def suite():
    return unittest.makeSuite(TestAbsoluteMove)

The error that is produced claim that there is no modules named 'TestAbsoluteMove' and TestContinuousMove'. Does anyone know how to get this code working?

Thanks

+2  A: 

Nose makes this sort of thing a no-brainer. It will auto-detect your tests and run them as a suite. (You can also run specific tests by passing it a flag.)

Alison R.
+1  A: 

TestAbsoluteMove is a class, and it needs to come from somewhere. Wherever your AbsoluteMoveTestSuite class is defined, you need to import TestAbsoluteMove.

Adam Crossland
A: 

unittest is a bit of a pain to use like this. I would very much reommend that you follow Alison's advice a look at nose or use my personal favourite Python testing tool py.test. Just create functions following a specific naming convention and let it rip! The whole xUnit thing doesn't really fit into Python territory.

Noufal Ibrahim