我的标题是相当描述性的,但这里有。假设我有这个设置。
class BaseClass(object):
def __init__(self):
pass
def base_function(self, param="Hello World"):
print param
#multiple inheritance probably irrelevant but my problem deals with it
class DerivedClass(BaseClass, AnotherBaseClass):
def __init__(self):
pass
def advanced_function(self):
#blah blah blah
#code code code
self.base_function()
现在,我有一种情况,我正在测试派生类,但在这样做时,我需要确保调用它的基类方法。我试着做这样的事情
from mock import MagicMock
d = DerivedClass()
super(DerivedClass, d).base_function = MagicMock()
d.advanced_function()
super(DerivedClass, d).base_function.assert_called()
我 100% 确定这个设置是错误的,因为
AttributeError: 'super' object has no attribute 'base_function'
我知道我在 super 上做错了什么,有人知道吗?