Skip to main content

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

Project description

https://img.shields.io/pypi/v/celery-mock.svg https://img.shields.io/travis/ulamlabs/celery-mock.svg https://codecov.io/gh/ulamlabs/celery-mock/branch/master/graph/badge.svg

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

Rationale

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

pip install celery-mock

How to use

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()
        client.post('/api/users/', data={'username': 'konrad')  # runs tasks inline

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

        with task_mock('myapp.post_user_create_task'):
            client.post('/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()
        client.post('/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.

Files for celery-mock, version 1.1.7
Filename, size File type Python version Upload date Hashes
Filename, size celery_mock-1.1.7-py3-none-any.whl (5.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size celery-mock-1.1.7.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page