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

Chad Netzer cnetzer at mail.arc.nasa.gov
Wed Feb 12 02:17:26 CET 2003

On Tue, 2003-02-11 at 16:21, Fernando Perez wrote:
> Mark McEahern wrote:

> > 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.

I think the mix-in approach you gave is perfectly fine.  That is exactly
what multiple inheritence is for.  test1 and test2 ARE both a testBase
and a TestCase, and a TestCase is by definition what you want unittest
to run.

I'd call it _testBase, or something, to indicate it is supposed to be
subclassed (and so that .


class _testBase(): pass

class test1(_testBase,TestCase): pass

class test2(_testBase,TestCase): pass

More information about the Python-list mailing list