Unittest testloader and hierarchy of TestSuites

T

Tero Saarni

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top