@patch('__builtin__.open')
def test_write_out(mock_open, mock_pickle):
    path = '~/collection'
f = mock_open.return_value
f.method.return_value = path
write_out(path, 'data')
mock_open.assert_called_once_with('~/collection', 'wb')
mock_pickle.assert_called_once_with('data', f)
f.close.assert_any_call()
Mocking two functions with patch for a unit test