<p dir="auto">Requiring the user to ensure that only one instance of celerybeat exists across their cluster creates a substantial implementation burden (either creating a single point-of-failure or encouraging users to roll their own distributed mutex).</p>
<p dir="auto">celerybeat should either provide a mechanism to prevent inadvertent concurrency, or the documentation should suggest a best-practice approach.</p>
<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?utf8=%E2%9C%93&amp;q=is%3Aissue+label%3A%22Category%3A+Documentation%22+">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues in this issue<br>
(If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h1 dir="auto">Description</h1>
<p dir="auto">the part of the documentation describing <code class="notranslate">celery_app</code> and <code class="notranslate">celery_worker</code> fixtures has a test example that doesn't pass:</p>
<p dir="auto"><a href="https://github.com/celery/celery/blame/master/docs/userguide/testing.rst#L152">https://github.com/celery/celery/blame/master/docs/userguide/testing.rst#L152</a></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/21345604/189285498-fe7efa52-3a6e-45ae-bddf-a4610bc8ddff.png"><img src="https://user-images.githubusercontent.com/21345604/189285498-fe7efa52-3a6e-45ae-bddf-a4610bc8ddff.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">if we use this test as it is, it will fail because the task does not get registered in the worker:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/21345604/189286212-410e8958-f55c-4d59-b830-755f94f7a2c2.png"><img src="https://user-images.githubusercontent.com/21345604/189286212-410e8958-f55c-4d59-b830-755f94f7a2c2.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto"><code class="notranslate">celery.exceptions.NotRegistered: 'test_create_task.mul'</code></p>
<h1 dir="auto">Suggestions</h1>
<p dir="auto">the problem is that executed this way, the tasks are not registered in the worker. The way I found working is to override the <code class="notranslate">celery_app</code> fixture:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from celery import Celery
from celery.contrib.testing.worker import TestWorkController
from celery.result import AsyncResult
import pytest

@pytest.fixture
def celery_app(celery_app: Celery):

    @celery_app.task(name='xyz')
    def mul(x, y):
        &quot;&quot;&quot;register a task named 'test_create_task.mul'&quot;&quot;&quot;
        return x * y

    return celery_app



def test_create_task(celery_app: Celery, celery_worker: TestWorkController):    
    result: AsyncResult = celery_app.send_task('xyz', kwargs = {&quot;x&quot;: 2, &quot;y&quot;: 2})
    result.wait()
    assert result.get() == 4"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>
<span class="pl-k">from</span> <span class="pl-s1">celery</span>.<span class="pl-s1">contrib</span>.<span class="pl-s1">testing</span>.<span class="pl-s1">worker</span> <span class="pl-k">import</span> <span class="pl-v">TestWorkController</span>
<span class="pl-k">from</span> <span class="pl-s1">celery</span>.<span class="pl-s1">result</span> <span class="pl-k">import</span> <span class="pl-v">AsyncResult</span>
<span class="pl-k">import</span> <span class="pl-s1">pytest</span>

<span class="pl-en">@<span class="pl-s1">pytest</span>.<span class="pl-s1">fixture</span></span>
<span class="pl-k">def</span> <span class="pl-en">celery_app</span>(<span class="pl-s1">celery_app</span>: <span class="pl-v">Celery</span>):

    <span class="pl-en">@<span class="pl-s1">celery_app</span>.<span class="pl-en">task</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'xyz'</span>)</span>
    <span class="pl-k">def</span> <span class="pl-en">mul</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>):
        <span class="pl-s">"""register a task named 'test_create_task.mul'"""</span>
        <span class="pl-k">return</span> <span class="pl-s1">x</span> <span class="pl-c1">*</span> <span class="pl-s1">y</span>

    <span class="pl-k">return</span> <span class="pl-s1">celery_app</span>



<span class="pl-k">def</span> <span class="pl-en">test_create_task</span>(<span class="pl-s1">celery_app</span>: <span class="pl-v">Celery</span>, <span class="pl-s1">celery_worker</span>: <span class="pl-v">TestWorkController</span>):    
    <span class="pl-s1">result</span>: <span class="pl-v">AsyncResult</span> <span class="pl-c1">=</span> <span class="pl-s1">celery_app</span>.<span class="pl-en">send_task</span>(<span class="pl-s">'xyz'</span>, <span class="pl-s1">kwargs</span> <span class="pl-c1">=</span> {<span class="pl-s">"x"</span>: <span class="pl-c1">2</span>, <span class="pl-s">"y"</span>: <span class="pl-c1">2</span>})
    <span class="pl-s1">result</span>.<span class="pl-en">wait</span>()
    <span class="pl-k">assert</span> <span class="pl-s1">result</span>.<span class="pl-en">get</span>() <span class="pl-c1">==</span> <span class="pl-c1">4</span></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/21345604/189286546-3977cede-1719-4cc7-b8af-42e52fc536d6.png"><img src="https://user-images.githubusercontent.com/21345604/189286546-3977cede-1719-4cc7-b8af-42e52fc536d6.png" alt="image" style="max-width: 100%;"></a></p>