summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ftplib.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-05-04 16:10:30 (GMT)
committerGitHub <noreply@github.com>2017-05-04 16:10:30 (GMT)
commit9fb061ba9ca6021055ca5a9bac193aeb1211aba0 (patch)
treea3501d333684524646f0ed74458fe767cc4d97f1 /Lib/test/test_ftplib.py
parent0f7f67660653517a5b3ed93e4b658583ff4cd355 (diff)
downloadcpython-9fb061ba9ca6021055ca5a9bac193aeb1211aba0.zip
cpython-9fb061ba9ca6021055ca5a9bac193aeb1211aba0.tar.gz
cpython-9fb061ba9ca6021055ca5a9bac193aeb1211aba0.tar.bz2
Fix test_ftplib warning if IPv6 is not available (#1457)
DummyFTPServer now calls del_channel() on bind() error to prevent the following warning in TestIPv6Environment.setUpClass(): Warning -- asyncore.socket_map was modified by test_ftplib Before: {} After: {3: <test.test_ftplib.DummyFTPServer 127.0.0.1:0 at ...>}
Diffstat (limited to 'Lib/test/test_ftplib.py')
-rw-r--r--Lib/test/test_ftplib.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index cc1c19b..044ce45 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -218,12 +218,18 @@ class DummyFTPServer(asyncore.dispatcher, threading.Thread):
threading.Thread.__init__(self)
asyncore.dispatcher.__init__(self)
self.create_socket(af, socket.SOCK_STREAM)
- self.bind(address)
- self.listen(5)
- self.active = False
- self.active_lock = threading.Lock()
- self.host, self.port = self.socket.getsockname()[:2]
- self.handler_instance = None
+ try:
+ self.bind(address)
+ self.listen(5)
+ self.active = False
+ self.active_lock = threading.Lock()
+ self.host, self.port = self.socket.getsockname()[:2]
+ self.handler_instance = None
+ except:
+ # unregister the server on bind() error,
+ # needed by TestIPv6Environment.setUpClass()
+ self.del_channel()
+ raise
def start(self):
assert not self.active