running a PyUnit TestSuite
Steven Taschuk
staschuk at telusplanet.net
Wed Apr 30 09:58:27 EDT 2003
Quoth Achim Domma:
> I have a TestSuite which depends on the execution order of the tests. If I
> use the 'main' object provided by unittest.py I can not specify the
> execution order, so I set up a TestSuite by hand. But how should I run it? I
> found no easy way to pass a TestSuite for unittest.main. Any hint?
One way is to use the defaultTest argument to unittest.main:
#!/usr/bin/env python
import unittest
class TestCase1(unittest.TestCase):
def testFoo(self):
self.assert_(1)
class TestCase2(unittest.TestCase):
def testBar(self):
self.assert_(0)
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestCase2))
s.addTest(loader.loadTestsFromTestCase(TestCase1))
return s
if __name__ == '__main__':
unittest.main(defaultTest='suite')
But I do wonder why your tests need a given execution order. This
is contrary to the doctrine of unit tests, which holds that each
test should be independent.
--
Steven Taschuk staschuk at telusplanet.net
Every public frenzy produces legislation purporting to address it.
(Kinsley's Law)
More information about the Python-list
mailing list