有没有办法从子类调用父工厂的方法?
通常的super(ThisClass, self)
orParentClass.method(self)
方法不起作用,因为self
它不是类的实例,而是工厂返回的对象。
class SomethingFactory(factory.DjangoModelFactory):
# Meta, fields, etc
@factory.post_generation
def post(self, create, extracted, **kwargs):
# Some steps
class SomethingElseFactory(SomethingFactory):
@factory.post_generation
def post(self, create, extracted, **kwargs):
super(SomethingElseFactory, self).post(create, extracted, **kwargs)
错误是TypeError: super(type, obj): obj must be an instance or subtype of type
。
(快捷方式super().post(create, extracted, kwargs)
会产生相同的错误。)
如何SomethingFactory.post
从子类访问该父工厂方法?