Make Celery use Django's test database without task_always_eager

后端 未结 2 1068
误落风尘
误落风尘 2021-01-04 14:45

When running tests in Django applications that make use of Celery tasks I can\'t fully test tasks that need to get data from the database since they don\'t connect to the te

2条回答
  •  猫巷女王i
    2021-01-04 15:28

    A simple solution is to use celery.contrib.testing.worker.start_worker to spawn a Celery worker within the Django test process. Because it lives in the same process, it can access the default in-memory test database, but because it lives in its own thread, it isn't eager and the task_always_eager flag is not needed or recommended.

提交回复
热议问题