Python mock patch a function called by another function

First example suggests that f1() and f2() defined in the same module.
Hence the following should work:

from foo.bar import f2
from mock import patch

class MyTest(TestCase):

    @patch('foo.bar.f1')
    def test_f2_2(self, some_func):
        some_func.return_value = (20, False)
        num, stat = f2()
        self.assertEqual((num, stat), (40, False))

Patch is on the same as import: @patch('foo.bar.f1')

Here is a good answer on the issue:

http://bhfsteve.blogspot.nl/2012/06/patching-tip-using-mocks-in-python-unit.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)