[TIP] setup/teardown with multiple python modules

Maciej Dziardziel fiedzia at gmail.com
Sun May 20 15:38:20 PDT 2012

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.
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

More information about the testing-in-python mailing list