私のタイトルはかなり説明的ですが、ここに行きます。この設定があるとします。
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'
私はスーパーで何か間違ったことをしていることを知っています。誰かアイデアがありますか?