Unittest testloader and hierarchy of TestSuites

Tero Saarni terosaarni at hotmail.com
Wed Nov 26 17:32:57 CET 2003


Hi,

I have a module with several test case classes which each have
several test methods:

    class Foo(unittest.TestCase):
        def testMethod1(self):
        def testMethod2(self):

    class Bar(unittest.TestCase):
        def testMethod3(self):
        def testMethod4(self):

When the test suite is composed each of these methods will be
wrapped into a separate TestCase object (=one object per method).
Without knowing the details of the original unit test framework I 
would then expect all of them to be wrapped into single TestSuite
instance. The resulting hierarchy would be like:

TestSuite (representing the module)
    TestCase (representing testMethod1)
    TestCase (representing testMethod2)
    TestCase (representing testMethod3)
    TestCase (representing testMethod4)

However the TestLoader in unittest.py seems to build following
hierarchy:

TestSuite
    TestSuite
        TestCase (representing testMethod1)
        TestCase (representing testMethod2)         
    TestSuite
        TestCase (representing testMethod3)
        TestCase (representing testMethod4) 

Of course this still works since TestSuite is implemented to
make recursive calls into nested suites and TestSuite itself
doesn't actually do anything visible to the user.

My question is what would be the "correct" way to compose these
objects into TestSuite according to the unit test framework?

Best regards,
Tero





More information about the Python-list mailing list