[TIP] setup/teardown with multiple python modules

Herman Sheremetyev herman at swebpage.com
Sun May 20 18:04:34 PDT 2012


On Mon, May 21, 2012 at 7:38 AM, Maciej Dziardziel <fiedzia at gmail.com> wrote:
> I have rather broad question about proper way of providing
> functionality for writing functional tests by python package authors.
>
> I am writing application which uses package A and package B, for
> accessing two type of databases.
> Both of those provide its own TestCase inheriting from
> unittest.TestCase, to perform setup and teardown.
> In order to create functional test that accesses both databases, i can either:
>
> 1. Try dealing with multiple inheritance. This can easily become very
> tricky and i don't like this way.

This options actually shouldn't be that bad -- you can put your tests
into a plain class that doesn't inherit TestCase class and then make
two more empty classes that just inherit both your class and the
appropriate one from the individual frameworks. The runner will just
run your tests twice with different setup/teardowns.

I don't know if it's ideal but it should be fairly clean and understandable.

> 2. Write my own custom TestCase that reimplements functionality from
> both packages.
> 3. Move this functionality from TestCase to nose plugin.
>
> None of those seems to be "pythonic" for me. #1 may not be reliable.
> #2 Works, but requires
> some work on my side, but with a bit of help from package authors this
> could be simplified.
> #3 works too, but is tied to nose, and i would need a way to apply
> such plugins to only some of my tests.
>
> Ideally there should a way to have some kind of mixins or plugins for
> TestCase that would allow
> to combine behaviour from multiple packages, allowing me to specify
> which setup/teardowns i want to perform
> for each test or TestCase.
>
> Is there any existing or planned feature of unittest that would support that?
>
> --
> Maciej Dziardziel
> fiedzia at gmail.com
>
> _______________________________________________
> 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