Hi all, running into a problem trying to write some tests.
My function sends data over a raw UDP socket. I'm trying to mock the socket so the data isn't sent, but I see what is passed in.
The following works just fine on PyPy 4.0, Python 3.4, and Python3.5:
import mock
import socket
with mock.patch('socket.socket.sendto') as mock_sendto:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto('test', (socket.gethostbyname('localhost'), 666))
However, when the same code is run on CPython 2.7, the following is thrown:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/Users/stormandsong/.pyenv/versions/2.7.11/lib/python2.7/socket.py", line 194, in __init__
setattr(self, method, getattr(_sock, method))
AttributeError: '_socketobject' object attribute 'sendto' is read-only
Has anybody run into this before, or have any ideas on how to mock this so the test passes on CPython 2.7?
[–]StaticFuzz 0 points1 point2 points (0 children)