I have the following code:
my_module.py
def my_func(number):
def nested_func(value):
'''
Doing some calculation
'''
return result
output = []
for i in range(number):
res = nested_func(i)
output.append(res)
return output
I'm using pytest with pytest-mock and mocker as a fixture in test_my_module.py
test_my_module.py
def test_my_module(mocker):
expected_res = [1, 1, 1]
mocker.patch('nested_func', return_value=1)
from my_module import my_func
assert my_func(3) == expected_res
But when I run in py.test I got an error:
TypeError: Need a valid target to patch. You supplied: 'nested_func'
Is there any way to mocker.patch functions\methods, which are not visible in testing module and located as nested in that functions, I want to test?