Problem's running unittest test suite OO

Posted by chrissygormley on Stack Overflow See other posts from Stack Overflow or by chrissygormley
Published on 2010-04-09T10:08:34Z Indexed on 2010/04/09 10:13 UTC
Read the original article Hit count: 519

Filed under:
|
|

Hello,

I have a test suite to perform smoke tests. I have all my script stored in various classes but when I try and run the test suite I can't seem to get it working if it is in a class. The code is below: (a class to call the tests)

from alltests import SmokeTests

class CallTests(SmokeTests):

    def integration(self):

        self.suite()

if __name__ == '__main__':
    run = CallTests()
    run.integration()

And the test suite:

class SmokeTests():

    def suite(self): #Function stores all the modules to be tested 
        modules_to_test = ('external_sanity', 'internal_sanity')
        alltests = unittest.TestSuite()
        for module in map(__import__, modules_to_test):
            alltests.addTest(unittest.findTestCases(module))
        return alltests

    unittest.main(defaultTest='suite')

This output's an error: Attribute Error: 'module' object has no attribute 'suite'

So I can see how to call a normal function defined but I'm finding it difficult calling in the suite. In one of the tests the suite is set up like so:

class InternalSanityTestSuite(unittest.TestSuite):

# Tests to be tested by test suite
def makeInternalSanityTestSuite():
    suite = unittest.TestSuite()
    suite.addTest(TestInternalSanity("BasicInternalSanity"))
    suite.addTest(TestInternalSanity("VerifyInternalSanityTestFail"))
    return suite

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

Can anyone help me with getting this running?

Thanks for any help in advance.

© Stack Overflow or respective owner

Related posts about python

Related posts about classes