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


Groups > comp.lang.python > #107029

Re: How to parameterize unittests

Path csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Newsgroups comp.lang.python
Subject Re: How to parameterize unittests
Date Fri, 15 Apr 2016 10:20:18 +0200
Lines 35
Message-ID <mailman.5.1460708428.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> <5710A442.8000906@rece.vub.ac.be>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de Q7Yzt+Fl+P6aoaJv5vWQbw6ClI3rRu42yYPK41dmEoog==
Return-Path <antoon.pardon@rece.vub.ac.be>
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; 'received:134': 0.05; 'lines.': 0.07; 'rewrite': 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; 'instantiate': 0.16; 'paste.': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'tests.': 0.18; '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; 'header:User- Agent:1': 0.26; 'chris': 0.26; 'fri,': 0.27; 'module.': 0.27; 'see,': 0.27; "skip:' 10": 0.28; '15,': 0.30; 'received:be': 0.30; 'run': 0.33; 'class': 0.33; 'largely': 0.33; 'steven': 0.33; 'instance': 0.35; 'but': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'reuse': 0.66; 'cut': 0.67; 'directly.': 0.76; 'angelico:': 0.84; "d'aprano:": 0.84; 'pardon': 0.84; 'schreef': 0.84
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result ApQJAIOjEFeGuA9G/2dsb2JhbABehFQBM7wvhg4CggoBAQEBAQFmhGkBAQQjVQEQCw4KAgIFFgsCAgkDAgECAUUGDQYCAoglsB+NSIRQAQEBAQEFAQEBARx8hSWES4c/glYBBJgMgVWMOYkthWSPKWKDaWoBiUUBAQE
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0
In-Reply-To <CAPTjJmreV+Ed722t7mUUC62L2u8gT-CE5K9ASGon1PHMYFdmTQ@mail.gmail.com>
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 <5710A442.8000906@rece.vub.ac.be>
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> <CAPTjJmreV+Ed722t7mUUC62L2u8gT-CE5K9ASGon1PHMYFdmTQ@mail.gmail.com>
Xref csiph.com comp.lang.python:107029

Show key headers only | View raw


Op 15-04-16 om 09:42 schreef Chris Angelico:
> 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.

But the tests, at this moment, are not written to instantiate self.tree
but to call avltree directly. So I have to rewrite these tests. That
will IMO involve a lot of cut and paste.

-- 
Antoon.

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