unit testing class hierarchies

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Tue Oct 2 11:24:35 EDT 2012


Am 02.10.2012 16:06, schrieb Thomas Bach:
> 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?

Sorry, there's a misunderstanding: I want test_base() to be run as part 
of both TestD1 and TestD2, because it tests basic functions provided by 
both class D1 and D2.

Uli




More information about the Python-list mailing list