unit testing class hierarchies

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Tue Oct 2 12:54:41 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 classes D1 and D2. The instances of D1 and D2 are created in 
TestD1.setUp and TestD2.setUp and then used by all tests. There is no 
possible implementation creating such an instance for TestBase, since 
the baseclass is abstract.

Last edit for today, I hope that makes my intentions clear...

;)

Uli




More information about the Python-list mailing list