Celery 5 tasks, chains and groups tested in eager mode: working versions (tested 2026-10-15)
Define Celery tasks, chain and fan them out with groups, then test them offline with task_always_eager and the in-memory broker.
passed4 passed · 0 failed2026-10-15 13:13 UTC- Status
- passed
- Last passed
- 2026-10-15 13:13 UTC
- Tests
- 4 / 4
- Language
- Python
- Runtime
- Python 3.13.16
uv venv -q .venv && uv pip install -q --python .venv/bin/python -r requirements.txt .venv/bin/python -m pytest -q
Python 3.13.16 linux 6.17.0-1022-azure x64 runner: github-actions 38740169402
The code
Exactly the files that passed. Your agent can pull them with get_recipe("celery-tasks-eager-testing") (install), or see them on GitHub.
celery==5.6.3 pytest==9.1.1
from celery import Celery, chain, group
app = Celery("tasks", broker="memory://", backend="cache+memory://")
@app.task
def add(x, y):
return x + y
@app.task
def double(x):
return x * 2
def add_then_double(x, y):
return chain(add.s(x, y), double.s())
def sum_of_doubles(nums):
# fan out with a group, then reduce the results
return sum(group(double.s(n) for n in nums).apply_async().get())
import pytest
from tasks import app, add, add_then_double, sum_of_doubles
@pytest.fixture(autouse=True)
def eager():
app.conf.update(task_always_eager=True, task_eager_propagates=True)
yield
app.conf.update(task_always_eager=False)
def test_delay():
assert add.delay(2, 3).get() == 5
def test_chain():
assert add_then_double(2, 3).apply_async().get() == 10
def test_group():
assert sum_of_doubles([1, 2, 3]) == 12
def test_errors_propagate():
with pytest.raises(TypeError):
add.delay(1, "a").get()
[pytest] pythonpath = .
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.
Related stacks
Celery 5 on Redis with fakeredis-backed idempotency, tested offline in eager mode
Configure a Celery app on a Redis broker and result backend for production, guard a task with a Redis SET NX idempotency lock, and test it offline with task_always_eager and fakeredis.
Celery beat crontab schedules validated and run eagerly
Define beat_schedule crontab entries, validate task names and schedule types before deploy, and test each scheduled call offline with task_always_eager.
Django post_save signal enqueuing a Celery task, tested with eager mode and on_commit
A post_save signal queues a Celery task only after the row commits via transaction.on_commit, then tests run offline on in-memory SQLite with Celery eager mode and pytest-django's on_commit capture.