Skip to content

Commit cabe599

Browse files
authored
Hotfix (#166)
* Added README.rst to poetry version bump * Refactored yield -> return in all fixtures that makes sense * Cleanup * More code documentation
1 parent d5b614e commit cabe599

File tree

19 files changed

+78
-89
lines changed

19 files changed

+78
-89
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
|build-status| |coverage| |license| |semgrep| |pyversion| |pyimp| |ocbackerbadge| |ocsponsorbadge|
33

4-
:Version: 1.0.0 (TBD)
4+
:Version: 1.0.0a12
55
:Web: https://pytest-celery.readthedocs.io/en/latest/
66
:Download: https://pypi.org/project/pytest-celery/
77
:Source: https://github.com/celery/pytest-celery/

examples/myworker/tests/test_myworker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ def celery_worker_cluster(
1414
celery_worker: CeleryTestWorker,
1515
myworker_worker: CeleryTestWorker,
1616
) -> CeleryWorkerCluster:
17+
"""Add myworker worker to the workers cluster alongside the parametrize
18+
plugin worker."""
1719
cluster = CeleryWorkerCluster(celery_worker, myworker_worker) # type: ignore
1820
yield cluster
1921
cluster.teardown()
2022

2123

2224
def test_ping(celery_setup: CeleryTestSetup):
25+
"""Test ping task for each worker node."""
2326
worker: CeleryTestWorker
2427
for worker in celery_setup.worker_cluster:
2528
sig: Signature = ping.s()

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ version = "1.0.0a12"
6767
search = '__version__ = "{current_version}"'
6868
replace = '__version__ = "{new_version}"'
6969

70+
[tool.poetry_bumpversion.file."README.rst"]
71+
search = ':Version: {current_version}'
72+
replace = ':Version: {new_version}'
73+
7074
[tool.poetry.dependencies]
7175
python = ">= 3.8,<4.0"
7276
celery = { version = "^5", extras = ["redis", "pymemcache"] }

src/pytest_celery/api/backend.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
from pytest_celery.api.base import CeleryTestCluster
44
from pytest_celery.api.base import CeleryTestNode
5-
from pytest_celery.api.container import CeleryTestContainer
65
from pytest_celery.defaults import DEFAULT_WORKER_ENV
76

87

98
class CeleryTestBackend(CeleryTestNode):
10-
"""CeleryTestBackend is specialized node type for handling celery backends
11-
nodes. It is used to encapsulate a backend instance.
9+
"""This is specialized node type for handling celery backends nodes. It is
10+
used to encapsulate a backend instance.
1211
1312
Responsibility Scope:
1413
Handling backend specific requirements and configuration.
@@ -22,6 +21,8 @@ def default_config(cls) -> dict:
2221
}
2322

2423
def restart(self, reload_container: bool = True, force: bool = False) -> None:
24+
"""Override restart method to update the app result backend with new
25+
container values."""
2526
super().restart(reload_container, force)
2627
if self.app:
2728
self.app.conf.update(
@@ -30,24 +31,13 @@ def restart(self, reload_container: bool = True, force: bool = False) -> None:
3031

3132

3233
class CeleryBackendCluster(CeleryTestCluster):
33-
"""CeleryBackendCluster is a specialized cluster type for handling celery
34-
backends. It is used to define which backend instances are available for
35-
the test.
34+
"""This is a specialized cluster type for handling celery backends. It is
35+
used to define which backend instances are available for the test.
3636
3737
Responsibility Scope:
3838
Provude useful methods for managing a cluster of celery backends.
3939
"""
4040

41-
def __init__(self, *backends: tuple[CeleryTestBackend | CeleryTestContainer]) -> None:
42-
super().__init__(*backends)
43-
44-
def _set_nodes(
45-
self,
46-
*nodes: tuple[CeleryTestNode | CeleryTestContainer],
47-
node_cls: type[CeleryTestNode] = CeleryTestBackend,
48-
) -> tuple[CeleryTestNode]:
49-
return super()._set_nodes(*nodes, node_cls=node_cls)
50-
5141
@classmethod
5242
def default_config(cls) -> dict:
5343
return {

src/pytest_celery/api/base.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from abc import abstractmethod
4-
from typing import Any
54
from typing import Iterator
65

76
import pytest_docker_tools
@@ -14,9 +13,9 @@
1413

1514

1615
class CeleryTestNode:
17-
"""CeleryTestNode is the logical representation of a container instance. It
18-
is used to provide a common interface for interacting with the container
19-
regardless of the underlying implementation.
16+
"""This is the logical representation of a container instance. It is used
17+
to provide a common interface for interacting with the container regardless
18+
of the underlying implementation.
2019
2120
Responsibility Scope:
2221
The node's responsibility is to wrap the container and provide
@@ -44,6 +43,8 @@ def app(self) -> Celery:
4443
return self._app
4544

4645
def __eq__(self, other: object) -> bool:
46+
"""Two nodes are equal if they have the same container and Celery
47+
app."""
4748
if isinstance(other, CeleryTestNode):
4849
return all(
4950
(
@@ -152,8 +153,8 @@ def assert_log_does_not_exist(self, log: str, message: str = "", timeout: int =
152153

153154

154155
class CeleryTestCluster:
155-
"""CeleryTestCluster is a collection of CeleryTestNodes. It is used to
156-
collect the test nodes into a single object for easier management.
156+
"""This is a collection of CeleryTestNodes. It is used to collect the test
157+
nodes into a single object for easier management.
157158
158159
Responsibility Scope:
159160
The cluster's responsibility is to define which nodes will be used for
@@ -194,19 +195,24 @@ def nodes(self, nodes: tuple[CeleryTestNode | CeleryTestContainer]) -> None:
194195
self._nodes = self._set_nodes(*nodes) # type: ignore
195196

196197
def __iter__(self) -> Iterator[CeleryTestNode]:
198+
"""Iterate over the nodes of the cluster."""
197199
return iter(self.nodes)
198200

199-
def __getitem__(self, index: Any) -> CeleryTestNode:
201+
def __getitem__(self, index: int) -> CeleryTestNode:
202+
"""Get a node from the cluster by index."""
200203
return self.nodes[index]
201204

202205
def __len__(self) -> int:
206+
"""Get the number of nodes in the cluster."""
203207
return len(self.nodes)
204208

205209
def __eq__(self, other: object) -> bool:
210+
"""Two clusters are equal if they have the same nodes."""
206211
if isinstance(other, CeleryTestCluster):
207-
for node in self:
208-
if node not in other:
209-
return False
212+
if len(self) == len(other):
213+
for node in self:
214+
if node not in other:
215+
return False
210216
return False
211217

212218
@classmethod

src/pytest_celery/api/broker.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
from pytest_celery.api.base import CeleryTestCluster
44
from pytest_celery.api.base import CeleryTestNode
5-
from pytest_celery.api.container import CeleryTestContainer
65
from pytest_celery.defaults import DEFAULT_WORKER_ENV
76

87

98
class CeleryTestBroker(CeleryTestNode):
10-
"""CeleryTestBroker is specialized node type for handling celery brokers
11-
nodes. It is used to encapsulate a broker instance.
9+
"""This is specialized node type for handling celery brokers nodes. It is
10+
used to encapsulate a broker instance.
1211
1312
Responsibility Scope:
1413
Handling broker specific requirements and configuration.
@@ -22,6 +21,8 @@ def default_config(cls) -> dict:
2221
}
2322

2423
def restart(self, reload_container: bool = True, force: bool = False) -> None:
24+
"""Override restart method to update the app broker url with new
25+
container values."""
2526
super().restart(reload_container, force)
2627
if self.app:
2728
self.app.conf.update(
@@ -30,24 +31,13 @@ def restart(self, reload_container: bool = True, force: bool = False) -> None:
3031

3132

3233
class CeleryBrokerCluster(CeleryTestCluster):
33-
"""CeleryBrokerCluster is a specialized cluster type for handling celery
34-
brokers. It is used to define which broker instances are available for the
35-
test.
34+
"""This is a specialized cluster type for handling celery brokers. It is
35+
used to define which broker instances are available for the test.
3636
3737
Responsibility Scope:
3838
Provude useful methods for managing a cluster of celery brokers.
3939
"""
4040

41-
def __init__(self, *brokers: tuple[CeleryTestBroker | CeleryTestContainer]) -> None:
42-
super().__init__(*brokers)
43-
44-
def _set_nodes(
45-
self,
46-
*nodes: tuple[CeleryTestNode | CeleryTestContainer],
47-
node_cls: type[CeleryTestNode] = CeleryTestBroker,
48-
) -> tuple[CeleryTestNode]:
49-
return super()._set_nodes(*nodes, node_cls=node_cls)
50-
5141
@classmethod
5242
def default_config(cls) -> dict:
5343
return {

src/pytest_celery/api/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(
4949
self.ping = ping
5050

5151
def __len__(self) -> int:
52+
"""The total number of nodes in the setup."""
5253
return len(self._worker_cluster) + len(self._broker_cluster) + len(self._backend_cluster)
5354

5455
@property
@@ -88,6 +89,7 @@ def worker(self) -> CeleryTestWorker:
8889

8990
@classmethod
9091
def name(cls) -> str:
92+
"""The name of the setup."""
9193
# TODO: Possibly not needed/required refactoring
9294
return DEFAULT_WORKER_APP_NAME
9395

src/pytest_celery/api/worker.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212

1313
class CeleryTestWorker(CeleryTestNode):
14-
"""CeleryTestWorker is specialized node type for handling celery worker
15-
nodes. It is used to encapsulate a worker instance.
14+
"""This is specialized node type for handling celery worker nodes. It is
15+
used to encapsulate a worker instance.
1616
1717
Responsibility Scope:
1818
Managing a celery worker.
@@ -98,24 +98,13 @@ def get_running_processes_info(
9898

9999

100100
class CeleryWorkerCluster(CeleryTestCluster):
101-
"""CeleryWorkerCluster is a specialized cluster type for handling celery
102-
workers. It is used to define which worker instances are available for the
103-
test.
101+
"""This is a specialized cluster type for handling celery workers. It is
102+
used to define which worker instances are available for the test.
104103
105104
Responsibility Scope:
106105
Provude useful methods for managing a cluster of celery workers.
107106
"""
108107

109-
def __init__(self, *workers: tuple[CeleryTestWorker | CeleryTestContainer]) -> None:
110-
super().__init__(*workers)
111-
112-
def _set_nodes(
113-
self,
114-
*nodes: tuple[CeleryTestNode | CeleryTestContainer],
115-
node_cls: type[CeleryTestNode] = CeleryTestWorker,
116-
) -> tuple[CeleryTestNode]:
117-
return super()._set_nodes(*nodes, node_cls=node_cls)
118-
119108
@property
120109
def versions(self) -> set[str]:
121110
"""Celery versions of all workers in this cluster."""

src/pytest_celery/fixtures/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def celery_setup( # type: ignore
5555
@pytest.fixture
5656
def celery_setup_name(celery_setup_cls: type[CeleryTestSetup]) -> str: # type: ignore
5757
"""Fixture interface to the API."""
58-
yield celery_setup_cls.name()
58+
return celery_setup_cls.name()
5959

6060

6161
@pytest.fixture
@@ -64,7 +64,7 @@ def celery_setup_config(
6464
celery_worker_cluster_config: dict,
6565
) -> dict:
6666
"""Fixture interface to the API."""
67-
yield celery_setup_cls.config(
67+
return celery_setup_cls.config(
6868
celery_worker_cluster_config=celery_worker_cluster_config,
6969
)
7070

@@ -76,7 +76,7 @@ def celery_setup_app(
7676
celery_setup_name: str,
7777
) -> Celery:
7878
"""Fixture interface to the API."""
79-
yield celery_setup_cls.create_setup_app(
79+
return celery_setup_cls.create_setup_app(
8080
celery_setup_config=celery_setup_config,
8181
celery_setup_app_name=celery_setup_name,
8282
)

src/pytest_celery/vendors/memcached/fixtures.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ def default_memcached_backend_cls() -> type[MemcachedContainer]:
4141

4242
@pytest.fixture
4343
def default_memcached_backend_env(default_memcached_backend_cls: type[MemcachedContainer]) -> dict:
44-
yield default_memcached_backend_cls.env()
44+
return default_memcached_backend_cls.env()
4545

4646

4747
@pytest.fixture
4848
def default_memcached_backend_image(default_memcached_backend_cls: type[MemcachedContainer]) -> str:
49-
yield default_memcached_backend_cls.image()
49+
return default_memcached_backend_cls.image()
5050

5151

5252
@pytest.fixture
5353
def default_memcached_backend_ports(default_memcached_backend_cls: type[MemcachedContainer]) -> dict:
54-
yield default_memcached_backend_cls.ports()
54+
return default_memcached_backend_cls.ports()

0 commit comments

Comments
 (0)