How to parameterize unittests
Steven D'Aprano
steve at pearwood.info
Fri Apr 15 12:47:05 EDT 2016
On Fri, 15 Apr 2016 10:48 pm, Antoon Pardon wrote:
> 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
Right up to the moment that you realise that you need different tests for a
subclass, and now you can't using subclassing because they aren't
subclasses, they're completely independent classes that happen to duplicate
the same methods.
If the tests for your AVL tree and it's subclasses are *identical*, then
what's the point of the subclasses?
--
Steven
More information about the Python-list
mailing list