Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: How to parameterize unittests Date: Fri, 15 Apr 2016 18:35:04 +1000 Lines: 41 Message-ID: References: <570FA466.20003@rece.vub.ac.be> <570fb1a3$0$1609$c3e8da3$5496439d@news.astraweb.com> <57108FAC.3020105@rece.vub.ac.be> <5710A442.8000906@rece.vub.ac.be> <85inzjw9qf.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de ZnmYF7grN/1Km2lJhRSp5wOrmNZ3xH3wuVU/n1M+MI4g== Cancel-Lock: sha1:6FNXkqOV9Ut42s42Bq076VBfwp4= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'rewrite': 0.07; 'tests,': 0.07; 'api': 0.09; 'subject:How': 0.09; '8bit%:30': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; 'inheritance': 0.16; 'instantiate': 0.16; 'overriding': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'setup(self):': 0.16; 'tests.': 0.18; 'tree': 0.18; 'skip:l 40': 0.23; 'written': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'specify': 0.27; 'routine': 0.29; 'skip:s 30': 0.31; 'skip:d 40': 0.32; 'class': 0.33; 'instance': 0.35; 'supports': 0.35; 'but': 0.36; 'cases': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'things': 0.38; 'test': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; "you'll": 0.61; 'for:': 0.64; 'skip:\xe2 10': 0.70; '8bit%:43': 0.72; 'directly.': 0.76; '_o__)': 0.84; 'pardon': 0.84; 'received:125': 0.84; 'belief': 0.91; 'speaks': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <85inzjw9qf.fsf@benfinney.id.au> X-Mailman-Original-References: <570FA466.20003@rece.vub.ac.be> <570fb1a3$0$1609$c3e8da3$5496439d@news.astraweb.com> <57108FAC.3020105@rece.vub.ac.be> <5710A442.8000906@rece.vub.ac.be> Xref: csiph.com comp.lang.python:107033 Antoon Pardon writes: > But the tests, at this moment, are not written to instantiate > self.tree but to call avltree directly. That is exactly what the ‘TestCase.setUp’ method is for: to have the test case class specify how its test cases will customise themselves. class AVLTree_TestCase(unittest.TestCase): tree = AVLTree def setUp(self): super().setUp() self.test_instance = self.tree() def test_empty_tree_is_false(self): self.assertFalse(self.test_instance) class LoremIpsumAVLTree_TestCase(AVLTree_TestCase): tree = LoremIpsumAVLTree class DolorSitAmetAVLTree_TestCase(AVLTree_TestCase): tree = DolorSitAmetAVLTree By not overriding ‘setUp’, the same routine will be called in the subclass's instance also. > So I have to rewrite these tests. Yes, you'll need to consider inheritance and how the ‘unittest’ API supports it. -- \ “Faith, n. Belief without evidence in what is told by one who | `\ speaks without knowledge, of things without parallel.” —Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney