This is the code I want to test
file_handle = open('filename')
content = file_handle.read()
Now, in my test file, I want to mock open()
I tried using mockito when as below
when(open(...)).thenReturn(dummy_response)
This is the code I want to test
file_handle = open('filename')
content = file_handle.read()
Now, in my test file, I want to mock open()
I tried using mockito when as below
when(open(...)).thenReturn(dummy_response)
I found a way, which is not straightforward but works like a charm
import builtins
when(builtins).open(...).thenReturn(dummy_response)