Search code examples
pythontwisted

How can I dynamically generate a set of TestCase subclasses from another module?


I have one python module that defines a set of base classes which another python module then implements.

The core python module also has test cases that test if the base classes are correctly implemented.

In the second module's test suite, I would like to automatically generate the TestCase subclasses from the first module, and adding a mixin that does the necessary setUp() for the specific implementation.

I see lots of answers for parametrizing test cases, but in my case I just want to re-use the common classes and subclass all of them.

It's ok if it needs some code in the parent test module to instantiate them, as long as it names the tests differently and runs them all automatically.

If it matters, this code is using twisted and trial over standard unittest.


Solution

  • Something that may do almost exactly what you want is twisted.internet.test.reactormixins.ReactorBuilder. You can see how it's used in test_tcp, for example.