Skip to main content

Inspect Celery Queues with Pytest

I love Celery for background tasks, but testing them can be a headache. Usually, you have to run a worker or mock everything out. But sometimes you just want to know: "Did my task actually get queued in Redis?" and "Is the payload correct?"

That's why I put together pytest-celery-utils. It's a simple plugin that lets you peek directly into your Redis-backed Celery queues during your tests. No workers required—just pure inspection.

Installation

Grab it with uv:

uv add --dev pytest-celery-utils

Usage

Once installed, you get a celery_utils fixture. It's automatically available, so you can just drop it into your tests.

Here's how I use it to verify tasks are queuing up correctly:

def test_task_queued(celery_utils):
    # Fire off a task
    my_task.delay(arg1, arg2)

    # Get all queued tasks
    tasks = celery_utils.get_all_queued_tasks()
    assert len(tasks) > 0

    # Get tasks of specific type
    my_tasks = celery_utils.jobs_of_type("myapp.tasks.my_task")
    assert len(my_tasks) == 1

You'll need a celery_app fixture configured in your conftest.py so the plugin knows where to look:

import pytest
from celery import Celery

@pytest.fixture
def celery_app():
    # Make sure to point to your Redis instance
    return Celery("myapp", broker="redis://localhost:6379/0")

Features

  • Direct Redis Inspection: Look at what's actually in your queue without needing a running worker.
  • Task Counting: Easily assert that n jobs of a specific type are queued.
  • Job Filtering: Grab all jobs or filter them by task name (string or callable).
  • Queue Support: Inspects all queues defined in your Celery app.
  • Nested Data Access: Includes a handy dig utility for traversing those deeply nested Celery message dicts.

Limitations

Just a heads up: this is strictly for Redis brokers. If you're using RabbitMQ or SQS, this won't work for you. It's also designed for testing, so don't expect it to be blazing fast for production monitoring.

MIT License

Metadata

Release files for pytest-celery-utils 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-celery-utils 0.1.2
File Size Uploaded
pytest_celery_utils-0.1.2.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-celery-utils 0.1.2
File Interpreter ABI Platform
pytest_celery_utils-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 kB

Release files / pytest_celery_utils-0.1.2.tar.gz

Download URL pytest_celery_utils-0.1.2.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
08f20558ea980a99bbc69ed57be2a7b0505ed8b3630b0b14c0428663c6d69028
BLAKE2b-256 checksum
How to use checksums
14dcb61595979f0a468ec9196cdff18f2b1a279259931d51407cfc39c0a04ceb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pytest_celery_utils-0.1.2-py3-none-any.whl

Download URL pytest_celery_utils-0.1.2-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79b8776ad5e2518552f031fa73dfd8f34fa283dc4d4ecd721ac60cccb98f2c91
BLAKE2b-256 checksum
How to use checksums
3b9c57aa7769b0c35e7586d95fa149aa86c6dd1163532dbf511902bf0191cc4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page