Skip to content

Commit 4129415

Browse files
authored
Bugfix: Disabled clusters raised exception on len(celery_setup) (#197)
1 parent 3f08a58 commit 4129415

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/pytest_celery/api/setup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ def __init__(
5656

5757
def __len__(self) -> int:
5858
"""The total number of nodes in the setup."""
59-
return len(self._worker_cluster) + len(self._broker_cluster) + len(self._backend_cluster)
59+
nodes_count = 0
60+
if self.broker_cluster:
61+
nodes_count += len(self.broker_cluster)
62+
if self.backend_cluster:
63+
nodes_count += len(self.backend_cluster)
64+
if self.worker_cluster:
65+
nodes_count += len(self.worker_cluster)
66+
return nodes_count
6067

6168
@property
6269
def app(self) -> Celery:

tests/unit/api/test_setup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def test_disabling_backend_cluster(self, celery_setup: CeleryTestSetup):
8080
assert celery_setup.backend_cluster is None
8181
assert celery_setup.backend is None
8282

83+
def test_setup_length(self, celery_setup: CeleryTestSetup):
84+
assert len(celery_setup)
85+
8386
class test_disabling_broker_cluster:
8487
@pytest.fixture
8588
def celery_broker_cluster(self) -> CeleryBrokerCluster:
@@ -89,6 +92,9 @@ def test_disabling_broker_cluster(self, celery_setup: CeleryTestSetup):
8992
assert celery_setup.broker_cluster is None
9093
assert celery_setup.broker is None
9194

95+
def test_setup_length(self, celery_setup: CeleryTestSetup):
96+
assert len(celery_setup)
97+
9298
class test_disabling_worker_cluster:
9399
@pytest.fixture
94100
def celery_worker_cluster(self) -> CeleryWorkerCluster:
@@ -97,3 +103,6 @@ def celery_worker_cluster(self) -> CeleryWorkerCluster:
97103
def test_disabling_worker_cluster(self, celery_setup: CeleryTestSetup):
98104
assert celery_setup.worker_cluster is None
99105
assert celery_setup.worker is None
106+
107+
def test_setup_length(self, celery_setup: CeleryTestSetup):
108+
assert len(celery_setup)

0 commit comments

Comments
 (0)