Skip to content

Commit f2fed47

Browse files
authored
More documentation (#229)
* Added references to setup-matrix in appropriate places * Added advanced-installation-section reference * New Doc: Vendor Class
1 parent 4ec9454 commit f2fed47

File tree

4 files changed

+129
-4
lines changed

4 files changed

+129
-4
lines changed

docs/getting-started/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,4 @@ Quick Jump
260260

261261
.. tip::
262262

263-
See :ref:`advanced-installation` for more advanced installation options.
263+
See :ref:`advanced-installation-section` for more advanced installation options.

docs/getting-started/vendors.rst

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Backends
4242
Experimental brokers may be functional but are not confirmed to be
4343
production ready.
4444

45-
Enabled means that it is automatically added to the test setup matrix
45+
Enabled means that it is automatically added to the test :ref:`setup-matrix`
4646
when running the test suite :ref:`if the vendor dependencies are installed <installation>`.
4747

4848
.. warning::
@@ -67,6 +67,8 @@ The Dockerfile is published with the source code and can be found using
6767
:language: docker
6868
:caption: pytest_celery.vendors.worker.Dockerfile
6969

70+
.. _custom-vendors:
71+
7072
Custom Vendors
7173
==============
7274

@@ -103,3 +105,124 @@ Custom Worker
103105
:show-inheritance:
104106
:inherited-members:
105107
:no-index:
108+
109+
.. _vendor-class:
110+
111+
Vendor Class
112+
============
113+
114+
The **Vendor Class** is an optional mechanism for OOP style configuration of the plugin's vendors.
115+
It allows registering a class that defines how does the vendor behave and configured.
116+
117+
The vendor class represents the vendor's container class that is used automatically by the plugin.
118+
119+
The following diagram shows the relationship between the vendor class and the vendor's infrastructure.
120+
121+
.. mermaid::
122+
123+
graph TD;
124+
Vendor[Vendor] --> BrokerComponent[Broker Component]
125+
Vendor --> BackendComponent[Backend Component]
126+
Vendor --> WorkerComponent[Worker Component]
127+
128+
BrokerComponent --> Comp
129+
BackendComponent --> Comp
130+
WorkerComponent --> Comp
131+
132+
subgraph Comp["Component"]
133+
Node[Node] --> Container[Container]
134+
end
135+
136+
Comp --> DefaultFixtures[Default Fixtures]
137+
Comp --> VendorClass[Vendor Class]
138+
VendorClass -. "You are here" .-> VendorClass
139+
DefaultFixtures <.-> VendorClass
140+
141+
style Vendor fill:#f9f,stroke:#333,stroke-width:4px
142+
style Comp fill:#ddf,stroke:#333,stroke-width:2px
143+
style Node fill:#eeffdd,stroke:#333
144+
style Container fill:#ffffee,stroke:#333
145+
style VendorClass fill:#ffeedd,stroke:#333
146+
147+
Use Cases
148+
~~~~~~~~~
149+
150+
.. warning::
151+
152+
It is used only to override the built-in vendors **containers**.
153+
154+
Registering a Vendor Class
155+
--------------------------
156+
157+
The plugin uses the vendor class to implement the default fixtures of the vendor.
158+
To override it, create your own vendor class and subclass the matching built-in vendor class
159+
to include the built-in fixtures implementation.
160+
161+
Worker Example
162+
##############
163+
164+
.. code-block:: python
165+
166+
class MyWorkerContainer(CeleryWorkerContainer):
167+
@property
168+
def client(self) -> Any:
169+
return self
170+
171+
@classmethod
172+
def version(cls) -> str:
173+
return celery.__version__
174+
175+
@classmethod
176+
def log_level(cls) -> str:
177+
return "INFO"
178+
179+
@classmethod
180+
def worker_name(cls) -> str:
181+
return "my_tests_worker"
182+
183+
@classmethod
184+
def worker_queue(cls) -> str:
185+
return "my_tests_queue"
186+
187+
def post_initialization_logic(self) -> None:
188+
pass
189+
190+
And then, register it using the matching default fixture.
191+
192+
.. code-block:: python
193+
194+
@pytest.fixture
195+
def default_worker_container_cls() -> Type[CeleryWorkerContainer]:
196+
return MyWorkerContainer
197+
198+
.. warning::
199+
200+
The worker vendor requires another fixture to be registered to allow configuring the worker
201+
before it gets built.
202+
203+
.. code-block:: python
204+
205+
@pytest.fixture(scope="session")
206+
def default_worker_container_session_cls() -> Type[CeleryWorkerContainer]:
207+
return MyWorkerContainer
208+
209+
There's no ``session`` vendor class for other vendors.
210+
211+
- For RabbitMQ Broker use :func:`default_rabbitmq_broker_cls <pytest_celery.vendors.rabbitmq.fixtures.default_rabbitmq_broker_cls>`.
212+
- For Redis Broker use :func:`default_redis_broker_cls <pytest_celery.vendors.redis.broker.fixtures.default_redis_broker_cls>`.
213+
- For Redis Backend use :func:`default_redis_backend_cls <pytest_celery.vendors.redis.backend.fixtures.default_redis_backend_cls>`.
214+
- For Memcache Backend use :func:`default_memcached_backend_cls <pytest_celery.vendors.memcached.fixtures.default_memcached_backend_cls>`.
215+
216+
Accessing the Vendor Class
217+
--------------------------
218+
219+
Once a vendor class has been registered, it can be accessed using the :ref:`test-setup`.
220+
Any additional API added to the class can be accessed as well.
221+
222+
For example,
223+
224+
.. code-block:: python
225+
226+
def test_accessing_post_initialization_logic(celery_setup: CeleryTestSetup):
227+
worker: MyWorkerContainer = celery_setup.worker
228+
worker.post_initialization_logic()

docs/includes/installation.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ the plugin will allow extending the default configurations, up to the supported
2929
.. warning::
3030

3131
If you don't install any vendor (e.g. no extras and no manual installation), the plugin will result in an
32-
empty setup matrix and might not be fully functional.
32+
empty :ref:`setup-matrix` and might not be fully functional.
3333

3434
To install the vendors, you may either install all of the dependencies manually, or use the following extras:
3535

docs/userguide/advanced-installation.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
:Release: |version|
88
:Date: |today|
99

10-
The pytest-celery plugin uses the environment dependencies to install and configure the default setup matrix.
10+
The pytest-celery plugin uses the environment dependencies to install and configure the default :ref:`setup-matrix`.
1111
The available dependencies are the feature flags for the available :ref:`vendors`.
1212

1313
This guide will explain how to install the plugin, how to use the dependencies feature flags and how to
@@ -21,6 +21,8 @@ We will start by reviewing the standard installation instructions.
2121

2222
.. include:: ../includes/installation.txt
2323

24+
.. _advanced-installation-section:
25+
2426
Advanced Installation
2527
=====================
2628

0 commit comments

Comments
 (0)