3
方法置き換える:Pythonのmock.patch:私はモックとクラスでメソッドを置き換えるしたい
from unittest.mock import patch
class A(object):
def method(self, string):
print(self, "method", string)
def method2(self, string):
print(self, "method2", string)
with patch.object(A, 'method', side_effect=method2):
a = A()
a.method("string")
a.method.assert_called_with("string")
を...しかし、私は、コンピュータによって侮辱を受ける:
TypeError: method2() missing 1 required positional argument: 'string'