[issue12600] Support parameterized TestCases in unittest

Nick Coghlan report at bugs.python.org
Tue Jan 17 12:33:16 CET 2012


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Back on topic...

While I can see the advantage of parameterisation at the level of individual tests, I'm not at all clear on the benefits at the TestCase level.

For CPython's own test suite, if we want to share tests amongst multiple test cases, we just use ordinary inheritance. You get parameterisation pretty much for free with that approach:

class _BaseTest(object):
    # Tests go here
    # setUp and tearDown often go here, too

class FooTestCase(_BaseTest, TestCase):
    # Parameter settings go here

class BarTestCase(_BaseTest, TestCase):
    # Parameter settings go here

If you want to get data-driven about it, you can also do dynamic TestCase creation based on a sequence of parameter sets.

So, absent a compelling explanation for why the ordinary inheritance mechanisms aren't adequate, I'd be in favour of closing this one.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12600>
_______________________________________


More information about the Python-bugs-list mailing list