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'