python中是否有任何等效的严格模拟?一些报告意外调用模拟方法的机制(本示例中的 action.step2() ),就像 GoogleMock 框架中的这样。
class Action:
def step1(self, arg):
return False
def step2(self, arg):
return False
def algorithm(action):
action.step1('111')
action.step2('222')
return True
class TestAlgorithm(unittest.TestCase):
def test_algorithm(self):
actionMock = mock.create_autospec(Action)
self.assertTrue(algorithm(actionMock))
actionMock.step1.assert_called_once_with('111')