unittest help needed!

Oltmans rolf.oltmans at gmail.com
Thu Jan 14 20:13:46 CET 2010

On Jan 14, 11:46 pm, exar... at twistedmatrix.com wrote:
> When you run test.py, it gets to the loadTestsFromName line.  There, it
> imports the module named "test" in order to load tests from it.  To
> import
> that module, it runs test.py again.  By the time it finishes running the
> contents of test.py there, it has run all of your tests once, since part
> of test.py is "suite.run(r)".  Having finished that, the import of the
> "test"

Many thanks, really appreciate your insight. Very helpful. I need a
program design advice. I just want to know what's the gurus way of
doing it? I've a unittest.TestCase derived class that have around 50
test methods. Design is almost similar to following
import unittest

class result(unittest.TestResult):

class tee(unittest.TestCase):
    def test_first(self):
        print 'first test'
    def test_second(self):
        print 'second test'
    def test_third(self):
        print 'final method'

if __name__=="__main__":
    r = result()
    suite = unittest.defaultTestLoader.loadTestsFromName('test.tee')

As you can see, every test method is almost same. Only difference is
that every test method is calling process() with a different value.
Also, I've around 50 test methods coded that way. I just want to know:
is there a way I can make things smaller/smarter/pythonic given the
current design? If you think any information is missing please let me
know. I will really really appreciate any insights. Many thanks in

More information about the Python-list mailing list