我将开始在我的项目中使用 django-rq。
Django integration with RQ, a Redis based Python queuing library.
测试使用 RQ 的 Django 应用程序的最佳实践是什么?
例如,如果我想将我的应用程序作为黑盒进行测试,在用户执行某些操作后我想执行当前队列中的所有作业,然后检查我的数据库中的所有结果。我怎样才能在我的 django 测试中做到这一点?
最佳答案
我刚找到 django-rq
,它允许您在测试环境中启动一个工作线程,该工作线程执行队列中的任何任务然后退出。
from django.test impor TestCase
from django_rq import get_worker
class MyTest(TestCase):
def test_something_that_creates_jobs(self):
... # Stuff that init jobs.
get_worker().work(burst=True) # Processes all jobs then stop.
... # Asserts that the job stuff is done.
关于python - 在 Django 中测试 django-rq ( python-rq ) 的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11282346/