diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -28,20 +28,15 @@ ### Required services -Unit tests may require a running celery broker on your system (rabbitmq by -default). You can set the `BROKER_URL` environment variable to specify the url -to be used. - -If you do not want to use your system's broker (or do not want to have one -running), you shold use [[ https://github.com/jd/pifpaf | pifpaf ]] to take -care of that for you. - +Unit tests that require a running celery broker uses an in memory +broker/result backend by default, but you can configure it to use +true broker by settig `CELERY_BROKER_URL` and `CELERY_RESULT_BACKEND` +environment variables. For example: ``` -$ pifpaf --env-prefix PG run postgresql -- \ - pifpaf --env-prefix AMQP run rabbitmq nosetests +$ CELERY_BROKER_URL=amqp://localhost pifpaf run postgresql nosetests ..................................... ---------------------------------------------------------------------- diff --git a/swh/scheduler/tests/celery_testing.py b/swh/scheduler/tests/celery_testing.py --- a/swh/scheduler/tests/celery_testing.py +++ b/swh/scheduler/tests/celery_testing.py @@ -1,27 +1,13 @@ import os -import urllib from celery import current_app -CELERY_BROKER_PROTOCOLS = ['amqp', 'redis', 'sqs'] - - def setup_celery(): - broker_url = None - if 'BROKER_URL' in os.environ: - broker_url = os.environ['BROKER_URL'] - - elif 'PIFPAF_URLS' in os.environ: - urls = os.environ['PIFPAF_URLS'].split(';') - urls = [x.replace('rabbit://', 'amqp://') for x in urls] - for url in urls: - scheme = urllib.parse.splittype(url)[0] - if scheme in CELERY_BROKER_PROTOCOLS: - broker_url = url - break - if broker_url: - current_app.conf.broker_url = broker_url + broker_url = os.environ.get('CELERY_BROKER_URL', 'memory://') + result_backend = os.environ.get('CELERY_RESULT_BACKEND', 'cache+memory://') + current_app.conf.broker_url = broker_url + current_app.conf.result_backend = result_backend class CeleryTestFixture: