diff --git a/distributed/deploy/spec.py b/distributed/deploy/spec.py index bb46f81db88..445949dc200 100644 --- a/distributed/deploy/spec.py +++ b/distributed/deploy/spec.py @@ -315,7 +315,8 @@ async def scale_down(self, workers): scale_up = scale # backwards compatibility def __repr__(self): - return "SpecCluster(%r, workers=%d)" % ( + return "%s(%r, workers=%d)" % ( + type(self).__name__, self.scheduler_address, len(self.workers), ) diff --git a/distributed/deploy/tests/test_spec_cluster.py b/distributed/deploy/tests/test_spec_cluster.py index 0c062d3d3e0..e51e8f14260 100644 --- a/distributed/deploy/tests/test_spec_cluster.py +++ b/distributed/deploy/tests/test_spec_cluster.py @@ -81,6 +81,19 @@ def test_loop_started(): ) +@pytest.mark.asyncio +async def test_repr(): + worker = {"cls": Worker, "options": {"nthreads": 1}} + + class MyCluster(SpecCluster): + pass + + async with MyCluster( + asynchronous=True, scheduler=scheduler, worker=worker + ) as cluster: + assert "MyCluster" in str(cluster) + + @pytest.mark.asyncio async def test_scale(): worker = {"cls": Worker, "options": {"nthreads": 1}}