I have a specific test case in which I utilize the celery backend so I need the task_always_eager setting to be false or I will get a RuntimeError. The problem is however I need all other test cases ran with the setting true, so I am trying to set the celery config task_always_eager to false just for this test case using a celery mark annotation. However, It doesn't look like it is doing anything.
Here is a skeleton of my task:
@pytest.mark.celery(task_always_eager=False)
def test_task(self):
# do some stuff to start a task
do_stuff()
# do some stuff to get info on a task
get_info()
# assertions
Error:
def _ensure_not_eager(self):
if self.app.conf.task_always_eager:
raise RuntimeError(
"Cannot retrieve result with task_always_eager enabled")
E RuntimeError: Cannot retrieve result with task_always_eager enabled
/usr/local/lib/python3.6/site-packages/celery/backends/base.py:334: RuntimeError
TLDR: What am I doing wrong in this test case to set task_always_eager to false because it is not changing it when the test runs?
Celery's config object is dynamically updatable, so you can update it with:
celery.conf.task_always_eager = False
or celery.conf.CELERY_ALWAYS_EAGER = False
, if you're using pre- 4.0
Celery
You can do this on the fly, on a per-test basis, or during the "setUp" operation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.