Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'tests,': 0.07; 'unittest': 0.07; 'attribute.': 0.09; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'testcases': 0.09; 'def': 0.10; '(just': 0.16; 'eckhardt': 0.16; 'invoking': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'subject:class': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'library,': 0.17; '>>>': 0.18; 'bit': 0.21; 'own.': 0.22; 'help.': 0.22; "i'd": 0.22; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.28; 'run': 0.28; 'testcase': 0.29; 'class': 0.29; 'classes': 0.30; 'framework': 0.30; 'url:python': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'test': 0.36; 'problems': 0.36; 'skip:t 40': 0.37; 'ones': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'remove': 0.61; 'here': 0.65; 'decided': 0.65; 'otten': 0.84; 'yusuf': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: unit testing class hierarchies Date: Tue, 02 Oct 2012 19:40:38 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a441.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349199947 news.xs4all.nl 6932 [2001:888:2000:d::a6]:55968 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30648 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...