summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-06-30 15:04:48 (GMT)
committerGitHub <noreply@github.com>2017-06-30 15:04:48 (GMT)
commit45dba3af50cfa359dc2e40abe4306bd0b11d1315 (patch)
tree0569cc0618e0657c5ee4a121ed5b933207d52d38
parent00561189fb5d85826cfc907e3a72361e1a39a591 (diff)
downloadcpython-45dba3af50cfa359dc2e40abe4306bd0b11d1315.zip
cpython-45dba3af50cfa359dc2e40abe4306bd0b11d1315.tar.gz
cpython-45dba3af50cfa359dc2e40abe4306bd0b11d1315.tar.bz2
test_urllib2_localnet: clear server variable (#2510)
Set the server attribute to None in cleanup to avoid dangling threads.
-rw-r--r--Lib/test/test_urllib2_localnet.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index 716b6aa..f83f9cc 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -289,11 +289,15 @@ class BasicAuthTests(unittest.TestCase):
def http_server_with_basic_auth_handler(*args, **kwargs):
return BasicAuthHandler(*args, **kwargs)
self.server = LoopbackHttpServerThread(http_server_with_basic_auth_handler)
- self.addCleanup(self.server.stop)
+ self.addCleanup(self.stop_server)
self.server_url = 'http://127.0.0.1:%s' % self.server.port
self.server.start()
self.server.ready.wait()
+ def stop_server(self):
+ self.server.stop()
+ self.server = None
+
def tearDown(self):
super(BasicAuthTests, self).tearDown()
@@ -339,6 +343,7 @@ class ProxyAuthTests(unittest.TestCase):
return FakeProxyHandler(self.digest_auth_handler, *args, **kwargs)
self.server = LoopbackHttpServerThread(create_fake_proxy_handler)
+ self.addCleanup(self.stop_server)
self.server.start()
self.server.ready.wait()
proxy_url = "http://127.0.0.1:%d" % self.server.port
@@ -347,9 +352,9 @@ class ProxyAuthTests(unittest.TestCase):
self.opener = urllib.request.build_opener(
handler, self.proxy_digest_handler)
- def tearDown(self):
+ def stop_server(self):
self.server.stop()
- super(ProxyAuthTests, self).tearDown()
+ self.server = None
def test_proxy_with_bad_password_raises_httperror(self):
self.proxy_digest_handler.add_password(self.REALM, self.URL,
@@ -468,13 +473,17 @@ class TestUrlopen(unittest.TestCase):
f.close()
return b"".join(l)
+ def stop_server(self):
+ self.server.stop()
+ self.server = None
+
def start_server(self, responses=None):
if responses is None:
responses = [(200, [], b"we don't care")]
handler = GetRequestHandler(responses)
self.server = LoopbackHttpServerThread(handler)
- self.addCleanup(self.server.stop)
+ self.addCleanup(self.stop_server)
self.server.start()
self.server.ready.wait()
port = self.server.port