Below I have added some dummy code which exactly represent what I am trying to do.
I am importing a function from a class with an alias, I am doing this since the class is running the aliased version itself.
Things I have tried:
- http://bhfsteve.blogspot.com/2012/06/patching-tip-using-mocks-in-python-unit.html This does not give a specific solution to the problem.
- patched
a.dummy.class.function.aliasasa.dummy.class.functionthis allows execution but will not run the alias_function_mocker() as in the class the function is called as alias() and not function() - I tried running as
a.dummy.class.function.aliasbut this results in an attribute error as alias isn't actually an attribute of class(because function() is)
from a.dummy.class import function as alias
def alias_function_mocker():
return 0
@patch("a.dummy.class.function.alias", side_effect=alias_function_mocker):
def test_function(mocked_function):
function_calling_alias()
return 0
What I think the problem roots from is that the class file is calling function using alias and there doesn't seem to be a way to patch aliased function calls. The simple and most naive solution I can think of is just do not use an alias.