unittest: how to specify which suites to run with unittest.main()?

Fernando Perez fperez528 at yahoo.com
Wed Feb 12 01:21:47 CET 2003

Mark McEahern wrote:

>> Now I want to build a test suite which uses all the test* methdods
>> in test1 and test2, but NOT in testBase. testBase is meant to be
>> used only to provide common functionality to other test classes, not
>> to be used by itself.
> 1.  Don't name any method of testBase test*--or am I missing something?

Well, that doesn't work because I want to run those methods, but only from 
the test1/test2 instances.  These guys override the setUp() method to 
configure the tests with different parameters, but otherwise need to run 
exactly the same tests.  So having them inherit all the test* methods from 
testBase actually makes perfect sense: they inherit all the tests, 
configure the setUp() call differently, and go on happily.  So that 
solution doesn't work.

> 2.  Put testBase in a separate module and import it.

I thought of doing this, but it seems unnecessarily ugly. I like to have a 
single test.py file in my library code, and it would seem to me that there 
should be a way to tell unittest.main() exactly which test suite to run.

Thanks for the input, though.  I'm very new at this unittest business, so 
all ideas are appreciated.



More information about the Python-list mailing list