Art of Unit Testing

Christoph Zwerschke cito at online.de
Fri Aug 5 21:57:51 CEST 2005


I had tested the above only with Python 2.4 but I just noticed it does 
not work with Python 2.3. The following works also with Python 2.3:

import unittest

class MyTestCase(unittest.TestCase):
     def setUp(self):
         print "setUp",
     def tearDown(self):
         print "tearDown",
     def test1(self):
         print "test1"
     def test2(self):
         print "test2"

class MyTestSuite(unittest.TestSuite):
     def setUp(self):
         print "setUpAll",
     def tearDown(self):
         print "tearDownAll",
     def __call__(self, result):
         self.setUp()
         unittest.TestSuite.__call__(self, result)
         self.tearDown()

if __name__ == '__main__':
     suite = unittest.makeSuite(MyTestCase, suiteClass=MyTestSuite)
     unittest.TextTestRunner().run(suite)



More information about the Python-list mailing list