unit testing class hierarchies

Thomas Bach thbach at students.uni-mainz.de
Tue Oct 2 10:06:38 EDT 2012


On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote:
> As you see, the code for test_base() is redundant, so the idea is to
> move it to a baseclass:
> 
> class TestBase(unittest.TestCase):
>     def test_base(self):
>         ...
> 
> class TestD1(TestBase):
>     def test_r(self):
>         ...
>     def test_s(self):
>         ...
> 
> class TestD2(TestBase):
>     def test_x(self):
>         ...
>     def test_y(self):
>         ...

Could you provide more background? How do you avoid that test_base()
runs in TestD1 or TestD2?

To me it sounds like test_base() is actually no test. Hence, I would
rather give it a catchy name like _build_base_cls().  If a method name
does not start with 'test' it is not considered a test to run
automatically.

Does this help?

Regards,
	Thomas Bach.



More information about the Python-list mailing list