I'd like to patch a function which is called inside a decorator with the python mock library. I fail to be able to patch it though, resulting in the original function being called. It probably has to do with namespaces but it's not clear to me what I should use as function name, the first argument to the patch decorator.
What I have is the following:
def is_always_running_on_Windows_64bit_mode():
return True
class ToolsTests(BaseTestCase):
@patch('tools.is_running_on_Windows_64bit_mode', is_always_running_on_Windows_64bit_mode)
@parameters()
def test_benchmarks_in_x86_not_x64_folder(self):
...
#do some testing where the test decorator parameters should believe we're in 64 bit mode
...
BaseTestCase derives from unittest.TestCase and is defined in some other module. In that same module I have the decorator itself:
def parameters(*parameters):
def decorator(method, parameters=parameters):
if tools.is_running_on_Windows_64bit_mode():
regressions_folder = "Regressions_x64"
else:
regressions_folder = "Regressions"
# etc etc
return decorator
The problem is that tools.is_running_on_Windows_64bit_mode is called, not my own is_always_running_on_Windows_64bit_mode.
Searching for answers is a tad difficult as it's about decorating a decorator, if there's one out there already, I'm sorry for creating a redundant question.