Commit 92d90b06 authored by Jérome Perrin's avatar Jérome Perrin

software/erp5/test: fix ResourceWarning on python3

 - use the requests.Session in a context manager so that resources are
properly closed.
 - close the stdout of caucase process we want to keep silent

See merge request !1075
parents 68ac47df 98b7b05c
......@@ -110,6 +110,7 @@ class CaucaseService(ManagedResource):
'--netloc', backend_caucased_netloc,
'--service-auto-approve-count', '1',
],
# capture subprocess output not to pollute test's own stdout
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
......@@ -127,6 +128,7 @@ class CaucaseService(ManagedResource):
# type: () -> None
self._caucased_process.terminate()
self._caucased_process.wait()
self._caucased_process.stdout.close()
shutil.rmtree(self.directory)
......@@ -525,7 +527,7 @@ class TestHTTP(BalancerTestCase):
def test_keep_alive(self):
# type: () -> None
# when doing two requests, connection is established only once
session = requests.Session()
with requests.Session() as session:
session.verify = False
# do a first request, which establish a first connection
......@@ -539,6 +541,7 @@ class TestHTTP(BalancerTestCase):
new_conn.assert_not_called()
parsed_url = six.moves.urllib.parse.urlparse(self.default_balancer_url)
# check that we have an open file for the ip connection
self.assertTrue([
c for c in psutil.Process(os.getpid()).connections()
......
......@@ -64,7 +64,7 @@ class TestPublishedURLIsReachableMixin(object):
# erp5 site is not created, with 500 when mysql is not yet reachable, so we
# configure this requests session to retry.
# XXX we should probably add a promise instead
session = requests.Session()
with requests.Session() as session:
session.mount(
base_url,
requests.adapters.HTTPAdapter(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment