Skip to main content

Run a monitored Celery worker for integration tests that depend on Celery tasks

Project description

Build Status

celerytest - Integration testing with Celery

Writing (integration) tests that depend on Celery tasks is problematic. When you manually run a Celery worker together with your tests, it runs in a separate process and there’s no clean way to address objects targeted by Celery from your tests. When you use a separate test database (as with Django for example), you’ll have to duplicate configuration code so your Celery worker accesses the same database.

celerytest provides the ability to run a Celery worker in the background from your tests. It also allows your tests to monitor the worker and pause until Celery tasks are completed.

Using celerytest

To start a Celery worker in a separate thread, use:

app = Celery() # your Celery app
worker = start_celery_worker(app) # configure the app for our celery worker

To wait for the worker to finish executing tasks, use:

result = some_celery_task.delay()
worker.idle.wait() # optionally specify time-out


To use this with your django app through django-celery, get your app as such:

from import app
worker = start_celery_worker(app)


If you want to use this in a unittest TestCase, you can use CeleryTestCaseMixin. If you’re writing unit tests that depend on a celery worker, though, you’re doing it wrong. For unit tests, you’ll want to mock your Celery methods and test them separately. You could use CeleryTestCaseMixin to write integration tests with Celery tasks, though.

from unittest import TestCase
from celerytest.testcase import CeleryTestCaseMixin, setup_celery_worker
import time

app = Celery()
setup_celery_worker(app) # need to setup worker outside

class SomeTestCase(CeleryTestCaseMixin, TestCase):
    celery_app = app
    celery_concurrency = 4

    def test_something(self):
        result = multiply.delay(2,3)
        self.assertEqual(result.get(), 6)


To automatically launch a worker in the background while running a Lettuce integration test suite, add to

from lettuce import *
from celerytest import start_celery_worker
from app import app

def initial_setup(server):
    # memory transport may not work here
    world.celery = start_celery_worker(app, config="amqp")

def cleanup(server):

def after_step(step):
    # make sure we've received any scheduled tasks
    # allow tasks to complete


Install the latest version of celerytest from PyPI:

$ pip install celerytest

Or, clone the latest version of celerytest from GitHub and run setup:

$ git clone git://
$ cd celerytest
$ ./ install # as root

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 celerytest, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size celerytest-0.1.1.tar.gz (6.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page