[Pyunit-interest] How should I handle tests under different versions of Python
Brought to you by:
purcell
From: Patrick K. O'B. <po...@or...> - 2002-03-16 15:55:00
|
Are there any "standards" for writing unit tests that adapt to the specific version of Python being used to run the tests? Here is my situation. I'm adding unit tests to my PyCrust package, which is a Python shell that is similar to IDLE but uses wxPython instead of Tk. PyCrust includes certain introspection functions to support the display of command completion and call tips and a namespace tree view. These introspection routines should work on any Python object from any Python version back to 2.0 (at least in theory, but I'm adding the unit tests to make sure this is the case). In order to test the introspection routines against a variety of objects, I want to define some support classes (that make use of the new Python types) inside my unit test module. For example: class A(object): def __init__(self, a): self.a = a def foo(self): return "A" class B(A): def __init__(self, b): self.b = b def foo(self): return "B" + super(B, self).foo() class C(A): def foo(self): return "C" + super(C, self).foo() class D(C, B): def foo(self): return "D" + super(D, self).foo() But as soon as I do that the tests will fail to run under Python 2.1, where "object" and "super" do not exist. For whatever reason I can't think of an elegant way to handle this. And I was hoping someone who had already dealt with this could suggest an approach that fit nicely within the whole unit testing philosophy. Any suggestions? Thanks. --- Patrick K. O'Brien Orbtech |