Pytest plugin for inspecting Celery task queues in Redis during tests
Project description
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
njobs 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
digutility 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_celery_utils-0.1.2.tar.gz.
File metadata
- Download URL: pytest_celery_utils-0.1.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08f20558ea980a99bbc69ed57be2a7b0505ed8b3630b0b14c0428663c6d69028
|
|
| MD5 |
2d47c55f4c21aebcd8682eb359a936a5
|
|
| BLAKE2b-256 |
14dcb61595979f0a468ec9196cdff18f2b1a279259931d51407cfc39c0a04ceb
|
File details
Details for the file pytest_celery_utils-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pytest_celery_utils-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79b8776ad5e2518552f031fa73dfd8f34fa283dc4d4ecd721ac60cccb98f2c91
|
|
| MD5 |
6bb6faf5fcfee0ca2d1bf79c9c5521c1
|
|
| BLAKE2b-256 |
3b9c57aa7769b0c35e7586d95fa149aa86c6dd1163532dbf511902bf0191cc4e
|