[英]Get a list of Celery tasks from a django unit test
我想在運行單元測試時檢索在tasks.py
中注冊的所有任務的列表。
在我的正常環境中,我使用current_app.tasks檢索任務列表,但是不幸的是,在運行測試時,該列表只會返回:
<@task: celery.backend_cleanup of default:0x35d27b0>
<@task: celery.chain of default:0x35d27b0>
<@task: celery.chord of default:0x35d27b0>
<@task: celery.chord_unlock of default:0x35d27b0>
<@task: celery.chunks of default:0x35d27b0>
<@task: celery.group of default:0x35d27b0>
<@task: celery.map of default:0x35d27b0>
<@task: celery.starmap of default:0x35d27b0>
考慮到我的模型是正在調用任務的模型,因此正在導入時添加並評估了Celery任務,只是它們還沒有導入到current_app中。
一個簡單的解決方案是在單元測試文件夾的頂部執行import tasks
。
新秀錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.