I am trying to replace a function with itself, using different parameters.
Here is a sample. I can't share the real code, I'm on papery secrecy!
import unittest
from unittest.mock import patch
import mymodule
import production
class MyTest(unittest.TestCase):
@patch('production.mymodule.myfunction', lambda: mymodule.myfunction(devmode=True))
def test_main_with_mymodule_function_does_not_raise_exception(self):
# This is an integration test. myfunction is used within main.
try:
production.main()
except Exception as e:
self.fail(e)
As expected the following generates a recursive call:
@patch('production_code.mymodule.myfunction', lambda: mymodule.myfunction(devmode=True))
We basically decorate myfunction with a decorator that will call myfunction. We get a nice "Too many recursions" exception!
I need a way to replace myfunction(devmode=False) with myfunction(devmode=True). But because I am in an integration test, and testing main(), I have no direct access to the function's parameters. Thing is, I made this very integration test to test how myfunction integrates with everything else in main.
Ideally, I shouldn't even have to create a devmode parameter, but I'm running a heavy sql query that requires to be limited by adding "TOP(10)" to the query.
Thanks for your help! :)