My python file has many methods defined in it. In many of the methods in the file, I am calling a function - let's say "fun1".
I want to mock the 'fun1' function for each of the methods differently. Is there a way to patch an object differently at method level and not at file level?
Contents of aPythonFile.py
=======================================
import fun from a_module
def a():
res= fun(aarg1, aarg2)
return res
def b():
res = fun(barg1, barg2)
return res
This came to my mind, as I know, the same "fun" can be patched differently for different files, then why not be able to patch differently based on the method in the file where it is called :-
@mock.patch("package.aPythonFile.fun") - Is Valid
@mock.patch("package.aPythonFile.a.fun") - ?? (possible?)
@mock.patch("package.aPythonFile.b.fun") - ?? (possible?)