How to pass variables using Unittest suite

Posted by chrissygormley on Stack Overflow See other posts from Stack Overflow or by chrissygormley
Published on 2010-05-11T15:47:05Z Indexed on 2010/05/19 4:10 UTC
Read the original article Hit count: 403

Filed under:
|
|

Hello I have test's using unittest. I have a test suite and I am trying to pass variables through into each of the tests. The below code shows the test suite used.

class suite():

    def suite(self): #Function stores all the modules to be tested

        modules_to_test = ('testmodule1', 'testmodule2')
        alltests = unittest.TestSuite()
        for module in map(__import__, modules_to_test):
            alltests.addTest(unittest.findTestCases(module))
        return alltests

It calls tests, I would like to know how to pass variables into the tests from this class. An example test script is below:

class TestThis(unittest.TestCase):
    def runTest(self):
        assertEqual('1', '1')

class TestThisTestSuite(unittest.TestSuite):

    # Tests to be tested by test suite
    def makeTestThisTestSuite():
        suite = unittest.TestSuite()
        suite.addTest("TestThis")
        return suite

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


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

So from the class suite() I would like to enter in a value to change the value that is in assert value. Eg. assertEqual(self.value, '1'). I have tried sys.argv for unittest and it doesn't seem to work. Thanks for any help.

© Stack Overflow or respective owner

Related posts about python

Related posts about unittest