I have a function funcA
that lives in folderA.folderB.foo.py
def funcA():
...
return 0 if (some condition) else 1
That is then used in classB.funcB
in folderA.folderC.bar.py
.
from folderA.folderB.foo import funcA
class B:
def funcB(self):
return_code = funcA()
return 'A' if return_code == 0 else 'B'
Now in my testing suite I want to test classB.funcB
for both possible return_codes
that can be returned from funcA
, but I am not sure how to mock the return value of funcA
in a test for funcB
I have tried using @patch(folderA.folderB.foo.funcA)
as well as @patch(folderA.folderC.bar.funcA)
, but neither of these have worked. Based on what I have read from the documentation (https://docs.python.org/3.6/library/unittest.mock.html#where-to-patch) it seems that the latter is meant to work, but for some reason it doesn't work.