Skip to main content

The missing test library for the Celery Python library. Some of the things graveolens can help with include:

  • Provide resultss to Celery task calls without hitting your broker.

  • Ensuring that you know exactly which tasks are called.

  • Easily assert the arguments of task calls.

  • Easily handle results when using send_task in Celery.

The binomial name for celery is Apium graveolens.

Returning Results

from my_app.celery import app
import graveolens

def test_my_task():
    with graveolens.activate() as celery:
        celery.add('my_app.task', {'done': True, 'status': 'OK'})

        result = app.send_task('my_app.task', 'test', id=3)

        # The result is an EagerResult from Celery.
        assert result.get() == {'done': True, 'status': 'OK'}

        # You can also check ALL the calls that Celery received.
        assert len(celery.calls) == 1
        assert celery.calls[0].name == 'http://twitter.com/api/1/foobar'
        assert celery.calls[0].args == ('test', )
        assert celery.calls[0].kwargs == {'id': 3}

Asserting Celery Calls

By default, if a result is added and unused this raises an AssertionError when the context manager exits, e.g.:

import graveolens

def test_my_task():
    with graveolens.activate() as celery:
        celery.add('my_app.task')

    # Assertion will be raised here because 'my_app.task' is never called.

This can be configured using the assert_all_tasks_called flag to activate().

Additionally, if a Celery task is called without having a result set-up then graveolens.NotMockedTask will be raised.

from my_app.celery import app
import graveolens

def test_my_task():
    with graveolens.activate() as celery:
        try:
            result = app.send_task('my_app.task', 'test', id=3)
        except graveolens.NotMockedTask:
            # Exception will be raised since my_app.task has no result.
            pass

Metadata

Release files for graveolens 0.1.4

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

Built distribution (wheel)

Table of built distributions (wheels) for graveolens 0.1.4
File Interpreter ABI Platform
graveolens-0.1.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / graveolens-0.1.4-py2.py3-none-any.whl

Download URL graveolens-0.1.4-py2.py3-none-any.whl
Size 4.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d4311cfb664157bbe50e3074ce3ad2421ce69e0d57d815c9af11994254b45547
BLAKE2b-256 checksum
How to use checksums
7960f7767ce467f24d6787bfc44cc3b6cd199bac016c2fedd0a63dfcafa25200
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

Release history Release notifications | RSS feed

This release

0.1.4 This release

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

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