Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python客户端服务器脚本单元测试错误_Python_Unit Testing_Sockets_Python Unittest - Fatal编程技术网

Python客户端服务器脚本单元测试错误

Python客户端服务器脚本单元测试错误,python,unit-testing,sockets,python-unittest,Python,Unit Testing,Sockets,Python Unittest,我有提供/读取一些数据的客户端和服务器脚本 当我尝试使用PyUnit编写单元测试时,出现了一个错误,我无法解释它 以下是相关的代码片段: class TestSequenceFunctions(unittest.TestCase): def setUp(self): #some set up operations def testRecieve(self): s = socket.socket() s.connect((FEED_SERVER_HOST, FEED

我有提供/读取一些数据的客户端和服务器脚本

当我尝试使用PyUnit编写单元测试时,出现了一个错误,我无法解释它

以下是相关的代码片段:

class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
    #some set up operations

def testRecieve(self):
    s = socket.socket()   
    s.connect((FEED_SERVER_HOST, FEED_SERVER_PORT))
    sock = socket.socket()    
    #some recieve operations        
    s.close()

 # When i write this code snippet below, i get error: [Errno 98] Address already in use
error. I tried closing 's' socket in tearDown function but still same error raising.

    def testAnotherRecieve(self):
        sock = socket.socket() # Results ERRNO 98.
总之,我无法在unittest类中创建第二个套接字。什么原因可能导致此错误?

查看,在第二次测试启动时,套接字可能尚未关闭:

close()释放与连接关联的资源,但不释放 必须立即关闭连接。如果你想关闭 要及时连接,请在关闭()之前调用shutdown()