python - 在 Django 中测试 django-rq ( python-rq ) 的最佳实践

标签 python django testing python-rq

我将开始在我的项目中使用 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/

相关文章:

python - 在 pythonbrew 中使用 pip

python - 使用 Python ctypes 在整数格式之间进行转换

django - 使用 Queryset API 按组计算总和

android - Robolectric:窗口创建失败

python - 使用 re 分割字符串并将撇号内包含的子字符串分组在一起

python - 如何将此系列转换为嵌套 json 字符串?

python - Django:更改表单集错误消息

javascript - 在 JavaScript 文件中使用 Django 模板标签

java - 并行运行 maven 测试而不等待兄弟模块依赖项

testing - 使用持续集成,为什么测试在提交之后而不是之前运行?