@@ -42,7 +42,7 @@ Backends
4242Experimental brokers may be functional but are not confirmed to be
4343production 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 `
4646when 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+
7072Custom 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()
0 commit comments