I have two python files:
function.py:
def foo ():
return 20
def func ():
temp = foo()
return temp
and mocking.py:
from testing.function import *
import unittest
import mock
class Testing(unittest.TestCase):
def test_myTest(self):
with mock.patch('function.func') as FuncMock:
FuncMock.return_value = 'string'
self.assertEqual('string', func())
I want to mock func, but with no positive result. I have AssertionError: 'string' != 20. What should I do to mock it correctly ? If I do mock.patch ('func') I have TypeError: Need a valid target to patch. You supplied: 'func'. If I move func to mocking.py and call foo: function.foo() it works correctly. But how to do it when I don't want to move functions from function.py to mocking.py ?