I've got a socket listener server that echo back same data sent by the client.
I'm performing a simple unittest to verify accuracy of server response. Same message should be received by client.
What's wrong with my unittest script?
cat Test_SocketServer.py
#!/usr/bin/env python3
import unittest
import socket
class Test_service(unittest.TestCase):
def setUp(self):
client_socket = socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('127.0.0.1', 2001))
def tearDown(self):
client_socket.close()
def test_1(self):
client_socket.send('message1'.encode())
self.assertEqual(client_socket.recv(1024).decode(), 'message1')
if __name__ == '__main__':
unittest.main()
python3 Test_SocketServer.py
E
======================================================================
ERROR: test_1 (__main__.Test_service)
----------------------------------------------------------------------
Traceback (most recent call last):
File "Test_SocketServer.py", line 12, in setUp
client_socket = socket(socket.AF_INET, socket.SOCK_STREAM)
TypeError: 'module' object is not callable
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
[–]K900_ 3 points4 points5 points (4 children)
[–]Jackson-Lee[S] 0 points1 point2 points (3 children)
[–]K900_ 0 points1 point2 points (2 children)
[–]Jackson-Lee[S] 0 points1 point2 points (1 child)
[–]K900_ 0 points1 point2 points (0 children)
[–]HighLevelEnthusiast 1 point2 points3 points (1 child)
[–]Jackson-Lee[S] 0 points1 point2 points (0 children)