Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107028

Re: How to parameterize unittests

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: How to parameterize unittests
Date Fri, 15 Apr 2016 17:42:16 +1000
Lines 31
Message-ID <mailman.4.1460706139.6324.python-list@python.org> (permalink)
References <570FA466.20003@rece.vub.ac.be> <mailman.106.1460642951.15650.python-list@python.org> <570fb1a3$0$1609$c3e8da3$5496439d@news.astraweb.com> <57108FAC.3020105@rece.vub.ac.be> <CAPTjJmreV+Ed722t7mUUC62L2u8gT-CE5K9ASGon1PHMYFdmTQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de ScALwUQJ+ot4EuyF35jIbQZVwTX82XxiAHnv4Q1Lksiw==
Return-Path <rosuav@gmail.com>
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; 'lines.': 0.07; 'tests,': 0.07; 'unittest': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; 'subclass': 0.09; 'def': 0.13; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instantiate': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'tree': 0.18; 'tests': 0.18; 'thanks.': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'second': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'module.': 0.27; 'see,': 0.27; "skip:' 10": 0.28; '15,': 0.30; 'run': 0.33; 'class': 0.33; 'largely': 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'instance': 0.35; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'reuse': 0.66; 'cut': 0.67; 'chrisa': 0.84; "d'aprano:": 0.84; 'pardon': 0.84; 'schreef': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=MD0Yg1cddhRgzEMqHhSpVPytDIV0EGpX5s9b5m6kr/U=; b=xzIiP6uUWAsyGNcUIuBo0+q/kEBMSaaJLjK+mSX+JIHhKBU4aMA6Zrcmh0drg7F1N3 TikinC7cRNHiAva/DKC2An2Pm29k2T5xVwcowiUiwl2vGLIxa/2ah/VzJww1vSQTcbv1 tLPwcX+dvOMLL8xd+OffnnXDqXd0yudkYQ2xEFkpPNMxjYU3hEPRbH48PUoCrFdGLGNV HWvoD0KjDgKVqxZHvMLOpL5WGZ2cUznNq6t8xgV8ubx1rGeiVPzSIw0+D0EJSSCQpELP C7oS3ka3hPjqgU9Q1BFcY20D3UtWjVcM+6AbfIz7IoCawj2i3AOGSA43UwhpZnDOXBag DWsQ==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=MD0Yg1cddhRgzEMqHhSpVPytDIV0EGpX5s9b5m6kr/U=; b=mXB5kbzCP5kejyNsuBVP/gWE4Iwa2HOgQJnfHPo6j8EKSuJJwY4ngH4g3iiYI/H12k lKtZDiPXDYeBqoT5M8TfU7L0fEWX+S6+Is3HTSHGB6Vk777fmYRj03FhAix2LLnCXXWF +xr1O6NtRqtGSvfoOOr/gIc3oZzpgyESoOtxsQEKm526GLt3JsUvY56ApdPCRV4cEgXB PBvXZaH5qCWAq86Wh+rL1H6UFwLRfHKb3gER+aigm+WmNa46LhCB6F/lG2RZuNc+0jlR MkWK83M6A6bETexzcFpBZWELqj96gQzyMYE/RHlz5L0VL4FhuNp5TJqtIyiOAKOvOQOG OT2w==
X-Gm-Message-State AOPr4FWOHAPna7XEvVn2AOQspLE2/lOUZB+N4JlCqf9J4IMugDHtzNe99xy6tEIchSply6rat5QtGYEDJEuzEA==
X-Received by 10.50.23.80 with SMTP id k16mr3219495igf.94.1460706136868; Fri, 15 Apr 2016 00:42:16 -0700 (PDT)
In-Reply-To <57108FAC.3020105@rece.vub.ac.be>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAPTjJmreV+Ed722t7mUUC62L2u8gT-CE5K9ASGon1PHMYFdmTQ@mail.gmail.com>
X-Mailman-Original-References <570FA466.20003@rece.vub.ac.be> <mailman.106.1460642951.15650.python-list@python.org> <570fb1a3$0$1609$c3e8da3$5496439d@news.astraweb.com> <57108FAC.3020105@rece.vub.ac.be>
Xref csiph.com comp.lang.python:107028

Show key headers only | View raw


On Fri, Apr 15, 2016 at 4:52 PM, Antoon Pardon
<antoon.pardon@rece.vub.ac.be> wrote:
> Op 14-04-16 om 17:05 schreef Steven D'Aprano:
>> On Fri, 15 Apr 2016 12:08 am, Antoon Pardon wrote:
>>
>>> I have a unittest for my avltree module.
>>>
>>> Now I want this unittest to also run on a subclass of avltree.
>>> How can I organise this, so that I can largely reuse the
>>> original TestCase?
>>
>> class Test_AVLTree(unittest.TestCase):
>>     tree = avltree
>>
>>     def test_empty_tree_is_false(self):
>>         instance = self.tree()
>>         self.assertFalse(instance)
>>
>>
>> class Test_MySubclassTree(Test_AVLTree):
>>     tree = My_Subclass_Tree
>
> I see, that's going to be a lot of cut & pastes.
> Thanks.

Not really; the first class has all the tests, and the second one is
literally just those two lines. It overrides 'tree' (accessed inside
methods as 'self.tree'), and since all the tests are written to
instantiate self.tree, they are effectively parameterized.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to parameterize unittests Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-14 16:08 +0200
  Re: How to parameterize unittests Steven D'Aprano <steve@pearwood.info> - 2016-04-15 01:05 +1000
    Re: How to parameterize unittests Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-15 08:52 +0200
    Re: How to parameterize unittests Chris Angelico <rosuav@gmail.com> - 2016-04-15 17:42 +1000
    Re: How to parameterize unittests Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-15 10:20 +0200
      Re: How to parameterize unittests Steven D'Aprano <steve@pearwood.info> - 2016-04-15 19:10 +1000
        Re: How to parameterize unittests Michael Selik <michael.selik@gmail.com> - 2016-04-15 10:05 +0000
        Re: How to parameterize unittests Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-15 13:43 +0200
        Re: How to parameterize unittests Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-15 14:48 +0200
          Re: How to parameterize unittests Steven D'Aprano <steve@pearwood.info> - 2016-04-16 02:47 +1000
            Re: How to parameterize unittests Chris Angelico <rosuav@gmail.com> - 2016-04-16 03:51 +1000
            Re: How to parameterize unittests Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-16 22:37 +0200
    Re: How to parameterize unittests Serhiy Storchaka <storchaka@gmail.com> - 2016-04-15 11:24 +0300
    Re: How to parameterize unittests Chris Angelico <rosuav@gmail.com> - 2016-04-15 18:28 +1000
    Re: How to parameterize unittests Serhiy Storchaka <storchaka@gmail.com> - 2016-04-15 11:31 +0300
    Re: How to parameterize unittests Ben Finney <ben+python@benfinney.id.au> - 2016-04-15 18:35 +1000

csiph-web