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


Groups > comp.lang.python > #107054

Re: How to parameterize unittests

Path csiph.com!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 14:48:11 +0200
Lines 36
Message-ID <mailman.22.1460724628.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> <mailman.5.1460708428.6324.python-list@python.org> <5710affd$0$22140$c3e8da3$5496439d@news.astraweb.com> <5710D3DA.6030005@rece.vub.ac.be> <5710E30B.6050304@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 PLg2hLZNRRzeqkY5k+z69gUTTzgIfVFxTy53KcqpnGNg==
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.021
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'received:134': 0.05; 'subject:How': 0.09; 'before.': 0.09; 'def': 0.13; 'suggest': 0.15; 'prepend': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'tests': 0.18; 'variable': 0.18; 'parameter': 0.22; 'code.': 0.23; 'seems': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'right.': 0.27; 'idea': 0.28; 'that.': 0.30; 'too.': 0.30; 'code': 0.30; 'received:be': 0.30; 'class': 0.33; 'shift': 0.33; 'steven': 0.33; 'changing': 0.34; 'instance': 0.35; 'unit': 0.35; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'agree': 0.37; 'starting': 0.37; 'anything': 0.38; 'enough': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'more': 0.63; 'different': 0.63; 'else.': 0.66; 'here': 0.66; "d'aprano:": 0.84; 'schreef': 0.84
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result At4MAAfjEFeGuA9G/2dsb2JhbABehFQBvGSGDgKCBgEBAQEBAWaEaQEBBCNVEQsaAgUWCwICCQMCAQIBRRMIAoglsAeNQ4RQAQEIAh58hSWES4ULgjSCVgWNUoo6gVWMOYkthWSPKWKDaoowAQEB
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0
In-Reply-To <5710D3DA.6030005@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 <5710E30B.6050304@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> <5710A442.8000906@rece.vub.ac.be> <mailman.5.1460708428.6324.python-list@python.org> <5710affd$0$22140$c3e8da3$5496439d@news.astraweb.com> <5710D3DA.6030005@rece.vub.ac.be>
Xref csiph.com comp.lang.python:107054

Show key headers only | View raw


Op 15-04-16 om 13:43 schreef Antoon Pardon:
> Op 15-04-16 om 11:10 schreef Steven D'Aprano:
>> If you have code which is not parameterized, and you want to parameterize
>> it, you have to refactor. Unit tests are no different from anything else.
> I don't agree with that. If I have a piece of code that I want to parameterize,
> Often enough all I need to do is shift the code to the right. Prepend a def
> line and use a parameter with the same name as the more global variable I
> was using before. I don't need to change access to the variable in the code.

Some prelimary tests seems to suggest this idea might work here too.

Starting from this:

    class Test_AVLTree(unittest.TestCase):
 
        def test_empty_tree_is_false(self):
            instance = avltree()
            self.assertFalse(instance)

Changing it into this:

    def MakeAVLTest(avltree):
        class Test_AVLTree(unittest.TestCase):

            def test_empty_tree_is_false(self):
                instance = avltree()
                self.assertFalse(instance)

        return Test_AVLTree

    AVLTest = MakeAVLTest(avltree)
    MyTreeTest = MakeAVLTest(mytree)

Seems to work

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