unit testing class hierarchies
Fayaz Yusuf Khan
fayaz at dexetra.com
Tue Oct 2 11:05:33 EDT 2012
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.
--
Fayaz Yusuf Khan
Cloud architect, Dexetra SS, India
fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com
+91-9746-830-823
More information about the Python-list
mailing list