My unittest patch isn't working for a method I wrote that is called in another method that I'm currently trying to unit test. I'm not sure why the patch isn't working but I think it is because the method I'm trying to patch is in the same file as the method I'm trying to test.
Please see my code below:
In the src/main/python/storage_utils.py
file:
def bar(config_name):
return SimpleDataClass(dict(read_config(config_name)))
def foo(config_name, path, file_filter, params):
bar_info = bar(config_name)
return
My unit test:
from unittest.mock import patch
import storage_utils
class MyTestCase(unittest.TestCase):
@patch("src.main.python.storage_utils.bar")
def test_foo_success_path(self, mock_bar):
config_name, path, file_filter, params = 'test_config_name', 'test_path', 'test_file_filter', 'test_params'
mock_bar.return_value = SimpleDataClass({})
storage_utils.foo(config_name, path, file_filter, params)
I'm not sure what I'm doing wrong here as the foo
method still goes into the bar
method instead of mocking it and returning what's specified in the test case.