I have a production code to test (code_to_test) presented which requires me to mock the test of loading of pickle file to do some validations further.
def code_to_test():
#need to mock the below line
with open("path/to/file/model.pickle", "rb") as pickle_file:
model_dictionary = dill.load(pickle_file)
#some other stuff to validate based on the mock
I mocked as follows
from unittest.mock import patch
with patch("path.of.module.code_to_test.dill.load") as _mock:
_mock.return_value = some_dictionary_fixture
But it failed to test stating
When I tried to mock as follows, it shows up
ModuleNotFoundError
Update:
I also tried to Patch builtins.open
and use mock_open
(Like so - https://stackoverflow.com/a/34677735/7641555 ). But I am not sure how to use it to mock my case.