Pytest plugin for inspecting Celery task queues in Redis during tests
Project description
pytest-celery-utils
Pytest plugin for inspecting Celery task queues in Redis during tests.
This plugin provides utilities for testing Celery tasks without running workers, allowing you to inspect queued tasks directly from Redis.
Installation
uv add pytest-celery-utils
Requirements
- Python 3.11+
- Celery with Redis broker
- Redis server
Usage
The plugin automatically provides a celery_utils fixture that you can use in your tests:
def test_task_queued(celery_utils):
# Queue a task
my_task.delay(arg1, arg2)
# Check if task is queued
assert celery_utils.count_jobs_of_type("myapp.tasks.my_task") == 1
# 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
Configuration
You need to provide a celery_app fixture in your test configuration:
# conftest.py
import pytest
from celery import Celery
@pytest.fixture
def celery_app():
app = Celery("myapp", broker="redis://localhost:6379/0")
return app
API Reference
CeleryTestUtils
The main utility class providing methods for inspecting Celery queues.
Methods
-
get_all_queued_tasks() -> list[dict[str, Any]]Returns all tasks currently in the Redis queue(s). -
jobs_of_type(task: Union[str, Callable]) -> list[dict[str, Any]]Returns all tasks of a specific type. Can accept either a task name string or a task function. -
count_jobs_of_type(task: Union[str, Callable]) -> intReturns the count of tasks of a specific type.
Utility Functions
-
dig(path, data, *, default=None)Navigate nested dictionaries using dot-path notation or list of keys.from pytest_celery_utils import dig data = {"headers": {"task": "myapp.tasks.example"}} task_name = dig("headers.task", data) # or task_name = dig(["headers", "task"], data)
Limitations
- Only supports Redis broker (not RabbitMQ or other brokers)
- Designed for testing without workers running
- Not optimized for performance (intended for testing only)
License
MIT
Author
Michael Bianco (mike@mikebian.co)
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.0.tar.gz.
File metadata
- Download URL: pytest_celery_utils-0.1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"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 |
eb16b2b9d4b906faaca96e006d0fbff6b519ccc41866315c241cb839cf5da239
|
|
| MD5 |
18271791b9e7e2104e58a3ce0faf6f1b
|
|
| BLAKE2b-256 |
cef06f9a77794cd2c1c109dca693d77c79af36a2724284883108c9f315d620cd
|
File details
Details for the file pytest_celery_utils-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_celery_utils-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"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 |
422e0f205478c0654eee155c550cf6c8001328b7f14e0e2d3d3fb2605ecce2fd
|
|
| MD5 |
d2685a2d5e32d8f447515ef45639dd7c
|
|
| BLAKE2b-256 |
ea44bc71203f3e55ae5442c404df2991564567e820f78da5054109029303e77e
|