[TIP] parametrized testing and unittest2.TestCase
hnsbstn at gmail.com
Fri Dec 16 18:47:57 PST 2011
2011/12/16 holger krekel <holger at merlinux.eu>
> 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
Yes, a standalone lib of assert methods would work too. I created those
before and worked great but looking into how i can re-use unittest's ones.
> 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?
> No. What I have done in the past is to use assert statements but wrapping
them in methods where they get logged when executed. Logging is what i care
the most, useful for debugging for me. Currently I need to use unittest
TestCase not only for the assert statements but also so the tests can be
run without py.test as well. For this reason I realize that I cannot
paramterize tests at all.
For now I think will do without the parameterization until we can do
In any case, thanks for the reply. Good weekends!
> > Thanks
> > -hans
> > _______________________________________________
> > testing-in-python mailing list
> > testing-in-python at lists.idyll.org
> > http://lists.idyll.org/listinfo/testing-in-python
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python