Unable to invoke celery task in Django tests synchronously

I would like to access celery tasks synchronously during my Django tests, without having to run a celery worker. To achieve this, I specified CELERY_ALWAYS_EAGER=True in my .py settings, but it does not work. So I decided to apply the decorride_settings decorator to a specific test that looks like this:

 @override_settings(CELERY_ALWAYS_EAGER=True, BROKER_BACKEND='memory', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True) def test_foo(self): ... 

Unfortunately, this test still challenges my celery worker. What can i skip? To be specific, I am using Django 1.10 with Celery 4.0.0.

+5
source share
1 answer

In celery 4.0 configuration options changed,

Try them instead in your tests,

 @override_settings( task_eager_propagates=True, task_always_eager=True, broker_url='memory://', backend='memory' ) 

I ran into the same problem that was resolved using the new lowercase names for the tests, as well as in the celery default settings.

Below are the new settings for the initial map settings,
http://docs.celeryproject.org/en/latest/userguide/configuration.html#new-lowercase-settings

Celery settings change information:
http://docs.celeryproject.org/en/latest/whatsnew-4.0.html#lowercase-setting-names

+10
source

Source: https://habr.com/ru/post/1260081/


All Articles