我将在我的项目中开始使用django-rq。
Django与基于Redis的Python队列库RQ集成。
使用RQ测试django应用程序的最佳实践是什么?
例如,如果我想将我的应用程序作为一个黑匣子进行测试,在用户执行一些操作之后,我想要执行当前队列中的所有作业,然后检查我的DB中的所有结果。我怎么能在我的django测试中做到呢?
发布于 2012-08-07 12:07:43
在队列中仍有作业时,您需要测试暂停。为此,您可以检查Queue.is_empty()
,如果队列中仍然有作业,则可以挂起执行:
import time
from django.utils.unittest import TestCase
import django_rq
class TestQueue(TestCase):
def test_something(self):
# simulate some User actions which will queue up some tasks
# Wait for the queued tasks to run
queue = django_rq.get_queue('default')
while not queue.is_empty():
time.sleep(5) # adjust this depending on how long your tasks take to execute
# queued tasks are done, check state of the DB
self.assert(.....)
https://stackoverflow.com/questions/11282346
复制相似问题