[PATCH/RFC v3] Provide basic test fixture through inheritance
Dirk Wallenstein
halsmit at t-online.de
Sun Apr 17 18:05:33 EST 2011
On Thu, Apr 14, 2011 at 11:24:45AM +0800, Jeremy Kerr wrote:
> Hi Dirk,
>
> > Provide project and user objects for test cases through inheritance.
> > Just derive from BaseFixtureTestCase instead of the normal TestCase.
> > The provided objects are accessible as attributes.
>
> Looks good, seems like a good direction to go in.
>
> Do you think this would work as a stand-alone object, rather than one
> that is inherited by test cases? (ie, replacing the tests.utils.defaults
> object) I already have some inheritance in the current tests, and would
> rather avoid using multiple inheritance if at all possible.
Avoiding inheritance completely does not look to be feasible without
using a brittle "multiple interdependent statements" approach, because
the test case has to have a 'fixtures' attribute. I can make it a Mixin
that is as invisible as possible and there won't be a diamond hierarchy.
In case a Mixin is ok...
Would you like to see name mangling with double underscores for the
attributes '__user', '__projects', etc? And/Or would you prefer to have
all the attributes (like 'project_a') assembled in one additional
object? For access like:
self.defaults.project_a
I've written a meta-type that assembles all 'fixtures' attributes from
all classes in the inheritance hierarchy into one list, but refrained
from proposing it in favor of explicitness. Somebody who writes a test
case with multiple fixtures would have to know about clashes. But it's
there if you like it.
--
Cheers,
Dirk
More information about the Patchwork
mailing list