How to organize test cases with PyUnit

Donnal Walter donnal at donnal.net
Sun Jul 21 09:52:29 EDT 2002


Syver Enstad <syver-en+usenet at online.no> writes:
> If you want to build you're own TestSuite with all methods prefixed
> with test, you can do like this:
> 
> suite = TestSuite()
> suite.addTest(unit.cell_unit.Test('test1'))
> suite.addTest(unit.cell_unit.Test('test2'))
> 
> There is a TestLoader class (or hierarchy I can't remember) in
> unitttest.py that will do this automagically for you by introspecting
> your module and sucking out all TestCase derived classes and building
> TestSuite objects with all 'test' prefixed methods.
> 
> As for me I just put:
> 
> if __name__ == '__main__':
>     unittest.main()
> 
> In the bottom of my module and I can just run the module and it will
> be done for me.

Yes, from the responses here that does appear to be the conventional
way of doing things, so I guess I will continue using unittest this
way too. I had thought I might replace my batch files with a
TestSuite, but I'm really not complaining about the way it works now.
Thanks.

Donnal Walter



More information about the Python-list mailing list