If you are trying to check if it works MyClass.foo()correctly, you should not scoff at it.
Mocking - ; foo , some_module.bar(), some_module.bar() :
import some_module
class MyClass(object):
def foo(self, x, y, z):
result = some_module.bar(x, y, z)
return result[0] + 2, result[1] * 2, result[2] - 2
class TestMyClass(TestCase):
@mock.patch('some_module.bar')
def test_myclass(self, mocked_bar):
mocked_bar.return_value = (10, 20, 30)
mc = MyClass()
self.assertEquals(mc.foo('spam', 'ham', 'eggs'),
(12, 40, 28))
mocked_bar.assert_called_with('spam', 'ham', 'eggs')
mocked_bar.return_value , , mocked some_module.bar(). -- bar(), .
return_value, MagicMock(), , , mocked_bar, ..