unit testing class hierarchies

Peter Otten __peter__ at web.de
Tue Oct 2 13:40:38 EDT 2012


Fayaz Yusuf Khan wrote:

> Peter Otten wrote:
> 
>> Ulrich Eckhardt wrote:
>>> 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.
> How exactly are you invoking the test runner? unittest? nose? You can
> tell the test discoverer which classes you want it to run and which
> ones you don't. For the unittest library, I use my own custom
> load_tests methods:
> def load_tests(loader, tests, pattern):
>     testcases = [TestD1, TestD2]
>     return TestSuite([loader.loadTestsFromTestCase(testcase)
>                       for testcase in testcases])
> http://docs.python.org/library/unittest.html#load-tests-protocol
> 
>>> One way around this is to not derive class
>>> TestBase from unittest.
>> 
>> Another is to remove it from the global namespace with
>> 
>> del TestBase
> Removing the class from namespace may or may not help. Consider a
> scenario where someone decided to be creative with the cls.__bases__
> attribute.

Isn't that a bit far-fetched? I'd rather start simple and fix problems as 
they arise... 





More information about the Python-list mailing list