Is it possible to mock a global object, such as an imported module, in a specific method from a different module?
Example:
import some_module
class MyClass():
def a_method(self):
some_module.do_something(1)
def b_method(self):
some_module.do_something(2)
I would like to patch some_module
so as to set the return value of do_somthing()
, but only in a_method()
and not in b_method()
. Of course I could use a decorator, however I would like to patch from a different module.