Clean up a few more leaked FDs in tests
MODIFY
test/test_response.py
test/test_response.py
@@ -181,7 +181,9 @@ class TestResponse(unittest.TestCase):
# Try closing with an `httplib.HTTPResponse`, because it has an
# `isclosed` method.
- hlr = httplib.HTTPResponse(socket.socket())
+ sock = socket.socket()
+ self.addCleanup(sock.close)
+ hlr = httplib.HTTPResponse(sock)
resp2 = HTTPResponse(hlr, preload_content=False)
self.assertEqual(resp2.closed, False)
resp2.close()
@@ -198,7 +200,9 @@ class TestResponse(unittest.TestCase):
self.assertRaises(IOError, resp3.fileno)
def test_io_closed_consistently(self):
- hlr = httplib.HTTPResponse(socket.socket())
+ sock = socket.socket()
+ self.addCleanup(sock.close)
+ hlr = httplib.HTTPResponse(sock)
hlr.fp = BytesIO(b'foo')
hlr.chunked = 0
hlr.length = 3

MODIFY
test/with_dummyserver/test_https.py
test/with_dummyserver/test_https.py
@@ -472,6 +472,7 @@ class TestHTTPS(HTTPSDummyServerTestCase):
fingerprint = '92:81:FE:85:F7:0C:26:60:EC:D6:B3:BF:93:CF:F9:71:CC:07:7D:0A'
conn = VerifiedHTTPSConnection(self.host, self.port)
+ self.addCleanup(conn.close)
https_pool = HTTPSConnectionPool(self.host, self.port,
cert_reqs='CERT_REQUIRED',
ca_certs=DEFAULT_CA,

MODIFY
test/with_dummyserver/test_poolmanager.py
test/with_dummyserver/test_poolmanager.py
@@ -210,6 +210,7 @@ class TestPoolManager(HTTPDummyServerTestCase):
def test_http_with_ca_cert_dir(self):
http = PoolManager(ca_certs='REQUIRED', ca_cert_dir='/nosuchdir')
+ self.addCleanup(http.clear)
r = http.request('GET', 'http://%s:%s/' % (self.host, self.port))
self.assertEqual(r.status, 200)

Clean up a few more leaked FDs in tests