Метод первый: просто создайте издевайтесь над объектом и используйте его. Код выглядит так:
Код: Выделить всё
def test_one (self):
mock = Mock()
mock.method.return_value = True
# This should call mock.method and check the result.
self.sut.something(mock)
self.assertTrue(mock.method.called)
Код: Выделить всё
@patch("MyClass")
def test_two (self, mock):
instance = mock.return_value
instance.method.return_value = True
# This should call mock.method and check the result.
self.sut.something(instance)
self.assertTrue(instance.method.called)
Может ли кто-нибудь меня просветить?
Подробнее здесь: https://stackoverflow.com/questions/818 ... k-or-patch
Мобильная версия