with open('/some/path', 'w') as f:
    f.write('something')
file_handle = mock_open.return_value.__enter__.return_value
file_handle.write.assert_called_with('something')
How do I mock an open used in a with statement (using the Mock framework in Python)?