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


Groups > comp.lang.python > #107033

Re: How to parameterize unittests

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: How to parameterize unittests
Date 2016-04-15 18:35 +1000
Message-ID <mailman.9.1460709315.6324.python-list@python.org> (permalink)
References (2 earlier) <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> <85inzjw9qf.fsf@benfinney.id.au>

Show all headers | View raw


Antoon Pardon <antoon.pardon@rece.vub.ac.be> 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

Back to comp.lang.python | Previous | NextPrevious 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