@@ -272,6 +272,12 @@ Inline handlers can be used like this:
272272 Injecting signal handlers is using a similar pattern to adding tasks and can be done according
273273to the :ref: `signal-handlers-modules-injection ` section.
274274
275+ Tasks
276+ ~~~~~
277+
278+ The :ref: `default-tasks ` can be used out-of-the-box, but you can also add new tasks to the worker by creating a new module
279+ and injecting it into the environment. See :ref: `injecting-tasks ` for more information.
280+
275281Templates
276282=========
277283
@@ -283,6 +289,8 @@ Standalone Test Snippet
283289The following snippet can be used as a starting point for a bug report script. To use it, just copy and paste it into a
284290new file and run it with pytest.
285291
292+ The snippet is also part of the `CI system <https://github.com/celery/pytest-celery/actions/workflows/examples.yml >`_.
293+
286294RabbitMQ Management Broker
287295--------------------------
288296
@@ -298,117 +306,9 @@ Built-in Worker
298306
299307We'll use the :ref: `built-in-worker ` to use a specific Celery release.
300308
301- .. code-block :: python
302-
303- # flake8: noqa
304-
305- from __future__ import annotations
306-
307- import pytest
308- from celery import Celery
309- from celery.canvas import Signature
310- from celery.result import AsyncResult
311-
312- from pytest_celery import RABBITMQ_PORTS
313- from pytest_celery import CeleryBackendCluster
314- from pytest_celery import CeleryBrokerCluster
315- from pytest_celery import CeleryTestSetup
316- from pytest_celery import RabbitMQContainer
317- from pytest_celery import RabbitMQTestBroker
318- from pytest_celery import RedisTestBackend
319- from pytest_celery import ping
320-
321- # ##############################################################################
322- # RabbitMQ Management Broker
323- # ##############################################################################
324-
325-
326- class RabbitMQManagementTestBroker (RabbitMQTestBroker ):
327- def get_management_url (self ) -> str :
328- """ Opening this link during debugging allows you to see the
329- RabbitMQ management UI in your browser.
330- """
331- ports = self .container.attrs[" NetworkSettings" ][" Ports" ]
332- ip = ports[" 15672/tcp" ][0 ][" HostIp" ]
333- port = ports[" 15672/tcp" ][0 ][" HostPort" ]
334- return f " http:// { ip} : { port} "
335-
336-
337- @pytest.fixture
338- def default_rabbitmq_broker_image () -> str :
339- return " rabbitmq:management"
340-
341-
342- @pytest.fixture
343- def default_rabbitmq_broker_ports () -> dict :
344- # Expose the management UI port
345- ports = RABBITMQ_PORTS .copy()
346- ports.update({" 15672/tcp" : None })
347- return ports
348-
349-
350- @pytest.fixture
351- def celery_rabbitmq_broker (default_rabbitmq_broker : RabbitMQContainer) -> RabbitMQTestBroker:
352- broker = RabbitMQManagementTestBroker(default_rabbitmq_broker)
353- yield broker
354- broker.teardown()
355-
356-
357- @pytest.fixture
358- def celery_broker_cluster (celery_rabbitmq_broker : RabbitMQTestBroker) -> CeleryBrokerCluster:
359- cluster = CeleryBrokerCluster(celery_rabbitmq_broker)
360- yield cluster
361- cluster.teardown()
362-
363-
364- # ##############################################################################
365- # Redis Result Backend
366- # ##############################################################################
367-
368-
369- @pytest.fixture
370- def celery_backend_cluster (celery_redis_backend : RedisTestBackend) -> CeleryBackendCluster:
371- cluster = CeleryBackendCluster(celery_redis_backend)
372- yield cluster
373- cluster.teardown()
374-
375-
376- @pytest.fixture
377- def default_redis_backend_image () -> str :
378- return " redis:latest"
379-
380-
381- # ##############################################################################
382- # Worker Configuration
383- # ##############################################################################
384-
385-
386- @pytest.fixture (scope = " session" )
387- def default_worker_celery_log_level () -> str :
388- return " INFO"
389-
390-
391- @pytest.fixture (scope = " session" )
392- def default_worker_celery_version () -> str :
393- return " 5.2.7"
394-
395-
396- @pytest.fixture
397- def default_worker_app (default_worker_app : Celery) -> Celery:
398- app = default_worker_app
399- # app.conf... # Add any additional configuration here
400- return app
401-
402-
403- # ##############################################################################
404- # Bug Reproduction
405- # ##############################################################################
406-
407-
408- def test_issue_1234 (celery_setup : CeleryTestSetup):
409- sig: Signature = ping.s()
410- res: AsyncResult = sig.delay()
411- assert res.get() == " pong"
309+ .. literalinclude :: ../../examples/celery_bug_report.py
310+ :language: python
311+ :caption: examples.celery_bug_report.py
412312
413313Execute with Pytest
414314###################
0 commit comments