unittest "ResourceWarning: unclosed

时间:2024-05-20 17:46:32

将代码封装,并使用unittest调用时,返回如下警告:

C:\python3.6\lib\collections\__init__.py:431: ResourceWarning: unclosed <socket.socket fd=864, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.100.x.x', 37321), raddr=('10.1.x.x', 8500)>

 

解决办法,可以通过warnings库来忽略掉相关告警。

import warnings
warnings.simplefilter("ignore", ResourceWarning)

unittest "ResourceWarning: unclosed