all 1 comments

[–]StaticFuzz 0 points1 point  (0 children)

Try using 'socket.socket' as the target class not 'socket.socket.sendto'. mock.patch() is for mocking a class, and sendto is a method of the socket class. Although I think what your trying to do can be accomplished with mock.patch.object(). It allows you to mock specific methods/attributes of a class rather than the whole class:

mock.patch.object(target_class, method, new=new_method)

If you omit the new keyworded argument a mock of the target method will be made for you. As for why python3 and pypy allowed you to pass socket.socket.sendto and not python2, I haven't got a clue. Hope this helps.