[TIP] How do I run the same test on many different classes?

Andrew Bennetts andrew at bemusement.org
Sun Dec 13 15:50:12 PST 2009


Matthew Wilson wrote:
[...]
> I wrote a single unittest.TestCase class that tests for all the
> features I care about.  Pretend that the TestCase subclass is called
> TestTask and the class I want to make will be named Task.
> 
> I have several ideas about how to build this class and I want to use
> the TestTask class as a pass-fail filter.  Pretend I'll name each idea
> Task1, Task2, Task3, etc.
> 
> Then I want to pass Task1, Task2, etc into unittest.TestCase so it
> would run the tests on an instance of that class.

We do something similar in bzrlib.  https://launchpad.net/testscenarios is a
library that supports this without needing to install all of bzrlib.

The README explains how to use it:

<http://bazaar.launchpad.net/~lifeless/testscenarios/trunk/annotate/head%3A/README>

-Andrew.




More information about the testing-in-python mailing list