Mock file with string in Python This is an example on how to mock a file with string. Use case Testing a function which opens a file and does some kind of operation on it. About the example