From 448929870c2f8cb088d5eb9988e87e81d0d2ca2d Mon Sep 17 00:00:00 2001 From: Hendrik Makait Date: Mon, 1 Aug 2022 15:52:28 +0200 Subject: [PATCH] Use contextmanager to ensure clients are closed and do not leak --- distributed/deploy/tests/test_local.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/distributed/deploy/tests/test_local.py b/distributed/deploy/tests/test_local.py index 3c4a889ceed..d69e45b130a 100644 --- a/distributed/deploy/tests/test_local.py +++ b/distributed/deploy/tests/test_local.py @@ -1269,12 +1269,13 @@ def test_localcluster_start_exception(loop): pass -def test_localcluster_get_client(): +def test_localcluster_get_client(loop): with LocalCluster( - n_workers=0, asynchronous=False, dashboard_address=":0" + n_workers=0, asynchronous=False, dashboard_address=":0", loop=loop ) as cluster: - client1 = cluster.get_client() - assert client1.cluster == cluster - client2 = Client(cluster) - assert client1 != client2 - assert client2 == cluster.get_client() + with cluster.get_client() as client1: + assert client1.cluster == cluster + + with Client(cluster) as client2: + assert client1 != client2 + assert client2 == cluster.get_client()