Skip to main content

celery-mock allows you to mock celery task and then run them when you want

Project description

Celery Task Mocking

.. image::

.. image::

.. image::

celery-mock allows you to mock celery task and then run them when you want


Sometimes a celery task retries itself to wait for some event or model to change.
This is hard to test because celery tasks run (and retry) inline in tests.
Now you can choose when to run your tasks.

Supported versions

- Python 3 support
- Celery 3.1.x and 4.0.x support

How to install

.. code-block:: bash

pip install celery-mock

How to use

.. code-block:: python

from celery_mock import task_mock
from django.test import TestCase, Client

from myapp import dummyview

class UsersTestCase(TestCase):

def test_create_user(self):
client = Client()'/api/users/', data={'username': 'konrad') # runs tasks inline

with task_mock():'/api/users/', data={'username': 'konrad')
# no tasks started yet
# all tasks ran here

with task_mock('myapp.post_user_create_task'):'/api/users/', data={'username': 'konrad')
# all tasks started execept myapp.post_user_create_task
# myapp.post_user_create_task started here

# you can use task_mock manually:

tmock = task_mock().start()'/api/users/', data={'username': 'konrad')
# no tasks started yet
tomock.stop() # all tasks ran here

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
celery-mock-1.0.1.tar.gz (4.8 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page