Search code examples
pythonunit-testingtestingtest-suite

Test Suite unittest


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


Solution

  • 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.)