[TIP] parametrized testing and unittest2.TestCase

holger krekel holger at merlinux.eu
Fri Dec 16 14:18:52 PST 2011


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.

FWIW i am happy with using assert statements and not have to remember
the assert methods.  Do you see a particular shortcoming of using assert?

best,
holger

> 
> Thanks
> -hans

> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python




More information about the testing-in-python mailing list