I would like to test, using unittest, a method which reads from a file using a context manager:
with open(k_file, 'r') as content_file:
content = content_file.read()
I don't want to have to create a file on my system so I wanted to mock it, but I'm not suceeding much at the moment. I've found mock_open but I don't really understand how I'm supposed to use it and feed the mock as content_file in my test case. There is for instance this post here, but I do not understand how one is supposed to write this in a test case without modifying the original code.
Could anyone point me in the right direction?