I'm trying to mock a function call that executes when a module is imported, below is the sample of the issue that I'm having
app/module.py
from util import get_param
PARAM = get_param('param_name')
class sample():
def run_sample(self):
print(PARAM)
app/tests/test_module.py
from app import module
import unittest
class TestSample(unittest.TestCase):
@mock.patch('app.module.get_param')
def test_run_sample(self, mock_get_param):
test_obj = module.sample()
test_obj.run_sample()
This doesn't work and it calls the original get_param method instead of mocking it.