unit testing class hierarchies
Peter Otten
__peter__ at web.de
Tue Oct 2 10:32:48 EDT 2012
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):
> ...
>
> The problem here is that TestBase is not a complete test case (just as
> class Base is not complete), but the unittest framework will still try
> to run it on its own. One way around this is to not derive class
> TestBase from unittest.
Another is to remove it from the global namespace with
del TestBase
More information about the Python-list
mailing list