1

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.

Thomas Vander Stichele
  • 36,043
  • 14
  • 56
  • 60

1 Answers1

3

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.

Glyph
  • 31,152
  • 11
  • 87
  • 129
  • Thanks Glyph, that pointed me in the right direction. I took makeTestCaseClasses and changed it to a module function, using a list of generic test cases defined in the same module. The only thing that still puzzles me is the __metaclass__ = type at the top of the module; is that necessary ? What does it do ? It's pretty ungoogleable. – Thomas Vander Stichele Sep 05 '11 at 13:45
  • That just makes all classes defined in that module without an explicit base-class be new-style. It protects against somebody defining a throwaway class and forgetting the `(object)` before the `:`. – Glyph Sep 06 '11 at 00:04