Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'intermediate': 0.07; 'practice,': 0.07; 'tests.': 0.07; 'derived': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'discovery.': 0.16; 'eckhardt': 0.16; 'naming': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'header:User- Agent:1': 0.23; 'versions': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'am,': 0.29; 'everywhere': 0.31; 'mod': 0.31; 'class': 0.32; 'another': 0.32; 'implemented': 0.33; 'actual': 0.34; 'subject:from': 0.34; 'could': 0.34; 'classes': 0.35; 'common': 0.35; 'skip:s 30': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'module.': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'then,': 0.60; 'break': 0.61; 'received:173': 0.61; 'duplication': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Jan Reedy Subject: Re: subclassing from unittest Date: Thu, 23 May 2013 15:42:35 -0400 References: <07786a18-bb9f-4434-823c-d0fe00f858b0@cl9g2000vbb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369338168 news.xs4all.nl 16006 [2001:888:2000:d::a6]:34700 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45836 On 5/23/2013 2:58 AM, Ulrich Eckhardt wrote: > Well, per PEP 8, classes use CamelCaps, so your naming might break > automatic test discovery. Then, there might be another thing that could > cause this, and that is that if you have an intermediate class derived > from unittest.TestCase, that class on its own will be considered as test > case! If this is not what you want but you still want common > functionality in a baseclass, create a mixin and then derive from both > the mixin and unittest.TestCase for the actual test cases. This is now standard practice, gradually being implemented everywhere in the CPython test suite, for testing C and Py versions of a module. class TestXyz(): mod = None class TestXyz_C(TestXyz, TextCase): # Test C version mod = support.import_fresh_module('_xyz') # approximately right class TestXyz_Py(TestXyz, TextCase): # Test Python version mod = support.import_fresh('xyz') This minimizes duplication and ensures that both implementations get exactly the same tests. tjr