← ClaudeAtlas

celery-testslisted

Use whenever Python Celery tasks need unit or integration tests: pytest-celery celery_app and worker fixtures, apply() for synchronous calls, why task_always_eager misleads, and mocking task.retry to test retry behavior, for function and class-based tasks.
testland/qa · ★ 13 · Testing & QA · score 80
Install: claude install-skill testland/qa
# celery-tests ## Overview Per [docs.celeryq.dev/en/stable/userguide/testing.html][cel-test]: [cel-test]: https://docs.celeryq.dev/en/stable/userguide/testing.html > "Testing with Celery is divided into two parts: Unit & Integration: > Using `celery.contrib.pytest`. Smoke / Production: Using > [pytest-celery](https://pypi.org/project/pytest-celery/) >= 1.0.0" The test model uses pytest fixtures from the `celery.contrib.pytest` plugin (or the standalone `pytest-celery` package for newer versions). ## When to use - The repo has Celery task definitions (`@app.task` or `@shared_task`). - The user writes unit tests for the task body (no need for a real worker). - The user writes integration tests that require a real Celery worker thread. - A test verifies retry / chord / chain semantics. ## How to use 1. Confirm the repo has Celery tasks (`@app.task` / `@shared_task`) and pick the level: unit (task body) vs integration (real worker). 2. For unit tests, call the task function directly and assert its side effects; do NOT enable `task_always_eager` (Step 1, Step 2). 3. For retry logic, `unittest.mock.patch` the `<task>.retry` and the failing dependency, then assert `Retry` is raised (Step 3). 4. For an in-process synchronous run with no broker, invoke `task.apply(args=[...])` and assert on `result.successful()` / `result.result` (Step 5). 5. For integration tests that need a real worker, add the `celery_worker` (per-test) or `celery_session_worker` (p