Skip to content

Commit 3c4e2f0

Browse files
authored
Improved the celery bug report doc (#272)
1 parent 24c7e99 commit 3c4e2f0

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

docs/userguide/celery-bug-report.rst

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This guide will detail the process of creating example bug report scripts using
1515

1616
.. contents::
1717
:local:
18-
:depth: 2
18+
:depth: 3
1919

2020
Disable Setup Matrix
2121
====================
@@ -172,12 +172,10 @@ To install the worker from source, just run the test script from the `t/smoke/te
172172
It will automatically set up a `dev <https://github.com/celery/celery/blob/main/t/smoke/workers/dev.py>`_ worker for the test.
173173

174174
Tasks and Signals
175-
-----------------
175+
~~~~~~~~~~~~~~~~~
176176

177-
The plugin provides a :func:`ping task <pytest_celery.vendors.worker.tasks.ping>` by default, but there are other
178-
sources for tasks that can be used to reproduce a scenario.
179-
180-
To use the ping task, import it from the plugin.
177+
The plugin provides :ref:`default-tasks` by default. For example, to use the :func:`ping task <pytest_celery.vendors.worker.tasks.ping>`,
178+
import it from the plugin.
181179

182180
.. code-block:: python
183181
@@ -186,7 +184,7 @@ To use the ping task, import it from the plugin.
186184
The worker will already have it registered by default using the default worker volume.
187185

188186
Adding New Tasks
189-
################
187+
----------------
190188

191189
To add new tasks, create a new ``tasks.py`` module and use the :func:`default_worker_tasks <pytest_celery.vendors.worker.fixtures.default_worker_tasks>` fixture
192190
to inject the tasks into the worker as described in the :ref:`injecting-tasks` section.
@@ -200,7 +198,7 @@ For example, the tasks module can look like this:
200198
201199
202200
@shared_task
203-
def noop(*args, **kwargs) -> None:
201+
def mytask(*args, **kwargs) -> None:
204202
return celery.utils.noop(*args, **kwargs)
205203
206204
And then it can be injected into the worker like this:
@@ -218,17 +216,17 @@ And be used in a test like this:
218216

219217
.. code-block:: python
220218
221-
from tasks import noop
219+
from tasks import mytask
222220
223221
def test_issue_1234(celery_setup: CeleryTestSetup):
224222
# Running this canvas causes an unexpected exception as described in the bug report...
225-
assert noop.s().apply_async().get() is None, "The bug causes this assertion to fail..."
223+
assert mytask.s().apply_async().get() is None, "The bug causes this assertion to fail..."
226224
227225
Using Celery Tests Tasks
228-
########################
226+
------------------------
229227

230228
When running the test script from Celery's test suite, the worker already has access to all of the integration
231-
and smoke tests tasks, so you can use them to reproduce a scenario.
229+
and smoke tests tasks, in addition to the :ref:`default-tasks`, so you can use them to reproduce a scenario as well.
232230

233231
All you need to do is to import the tasks from the test suite and use them in the test case.
234232

@@ -251,7 +249,7 @@ For example,
251249
when publishing tasks.
252250

253251
Signal Handlers
254-
###############
252+
---------------
255253

256254
Signals can be connected inline in the test case, or by injecting a module with the signal handlers into the worker.
257255

@@ -272,12 +270,6 @@ Inline handlers can be used like this:
272270
Injecting signal handlers is using a similar pattern to adding tasks and can be done according
273271
to the :ref:`signal-handlers-modules-injection` section.
274272

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-
281273
Templates
282274
=========
283275

@@ -306,6 +298,9 @@ Built-in Worker
306298

307299
We'll use the :ref:`built-in-worker` to use a specific Celery release.
308300

301+
celery_bug_report.py
302+
--------------------
303+
309304
.. literalinclude:: ../../examples/celery_bug_report.py
310305
:language: python
311306
:caption: examples.celery_bug_report.py
@@ -346,6 +341,9 @@ Smoke Tests Worker
346341

347342
We'll use the smoke tests worker to run the worker from the source code.
348343

344+
celery_bug_report.py
345+
--------------------
346+
349347
.. code-block:: python
350348
351349
# flake8: noqa

0 commit comments

Comments
 (0)