我有一个看起来像这样的课:
from operators import Operation
class A():
def process(self, message):
Operation(message).execute()
我有这个测试:
class TestA(unittest.TestCase):
@mock.patch("path.to.A.Operation")
def test_create_assertion_processor(self, mock_operation):
message = {}
mock_operation_instance = mock.MagicMock
mock_operation.return_value = mock.MagicMock(return_value = mock_operation_instance)
A().process(message)
mock_operation.assert_called_once_with(message)
mock_operation_instance.execute.assert_called()
最后一行不起作用。我得到:
AttributeError: type object 'MagicMock' has no attribute 'execute'
我在这里做什么错了?
答案 0 :(得分:1)
我认为这只是一个错字,实例化您的第一个test
MagicMock