简体   繁体   中英

Get a list of Celery tasks from a django unit test

I would like to retrieve a list of all tasks that are registered in the tasks.py while running a unit test.

In my normal environment I use current_app.tasks to retrieve a list of tasks, but while running a test unfortunately that list just returns:

<@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 tasks are being added and evaluated on import, given the fact my models are the ones who were calling the tasks, they simply just haven't been imported into the current_app yet.

A simple solution was just doing a import tasks on top of the unit tests folder.

Rookie mistake.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM