[TIP] parametrized testing and unittest2.TestCase

Robert Collins robertc at robertcollins.net
Fri Dec 16 19:25:42 PST 2011


On Sat, Dec 17, 2011 at 11:18 AM, holger krekel <holger at merlinux.eu> wrote:
> Hi Hans,
>
> On Fri, Dec 16, 2011 at 13:00 -0800, Hans Sebastian wrote:
>> I need help and some suggestions. I run tests using py.test (latest from
>> pip) and use unittest2.TestCase as the base class for the tests. Today, I
>> am trying to parametrized multiple calls to a test function by following
>> the example in the online doc. I found that it only works with test class
>> that extends from *object* but not with the one that extends from *
>> unittest2.TestCase*. First of all, is this a bug or just not supported by
>> py.test?
>
> Indeed, py.test parametrization does not work with unittest2.TestCase.
> The unittest/unittest2 support of py.test aims at compatibility
> and invokes some not-so-easy-to-customize unittest code.  I think it'd
> be pretty hard to customize unittest2.TestCase to support
> parametrization and dynamic setups of test function arguments.
>
>> If not possible, what are alternative ways of parametrizing
>> testing but still want to reuse unittest2.TestCase's assert methods?
>
> Not sure but weren't there some libraries which provided these kind
> of assert methods in a standalone manner?  It may be possible to
> add a new way to run unittest.TestCases such that py.test's parametrized
> testing and funcargs work - at the cost of more limited compatibility.

testscenarios may either inspire or even help you with this.

-Rob



More information about the testing-in-python mailing list