I am working on a Django application. We're using celery to queue writes to our Mongo database. I'm trying to write a functional test (using Selenium) for a function that queues something in celery.

我正在研究Django应用程序。我们正在使用celery将写入队列排队到Mongo数据库。我正在尝试编写一个功能测试(使用Selenium)来为芹菜中的某些东西排队。

The problem is that celery writes to the main Mongo database instead of the test database. How can I set up my functional tests to work with an instance of celery that writes to the test database?

问题是芹菜写入主Mongo数据库而不是测试数据库。如何设置我的功能测试以使用写入测试数据库的芹菜实例?

We're using 'django_nose.NoseTestSuiteRunner' as our TEST_RUNNER.

我们使用'django_nose.NoseTestSuiteRunner'作为我们的TEST_RUNNER。

UPDATE:

更新:

I haven't been able to figure out how to use another instance of celery for the tests, but I have found a way to bypass celery for the functional tests.

我无法弄清楚如何使用芹菜的另一个实例进行测试,但我找到了绕过芹菜进行功能测试的方法。

In my settings.py:

在我的settings.py中:

FUNC_TEST_COMMAND=['functional']
func_test_command = filter(lambda element: element in FUNC_TEST_COMMAND, sys.argv)
if len(func_test_command) > 0:
  CELERY_ALWAYS_EAGER = True

This mimics the behaviour of an AsyncResult without sending anything through a message queue when running the functional test suite. (See http://celery.readthedocs.org/en/2.4/configuration.html#celery-always-eager for more info.)

这样可以模拟AsyncResult的行为,而无需在运行功能测试套件时通过消息队列发送任何内容。 (有关详细信息,请参阅http://celery.readthedocs.org/en/2.4/configuration.html#celery-always-eager。)

This solution is probably not ideal for functional tests, because it cuts out one of the application layers.

这种解决方案可能不适合功能测试,因为它会切断其中一个应用层。

2 个解决方案

#1


1

Using CELERY_ALWAYS_EAGER = True does indeed bypass Celery's asynchornous processing. In order to write to the test database, you'll need to start your celeryd worker using the connection settings to the test database.

使用CELERY_ALWAYS_EAGER = True确实绕过了Celery的异步处理。为了写入测试数据库,您需要使用测试数据库的连接设置启动您的celeryd worker。

更多相关文章

  1. python 之 自制测试框架
  2. 使用芹菜接收未注册的任务
  3. Python测试函数和类 笨方法学习Python
  4. Python 3.4 AssertEqual()在Django单元测试中使用时的未预测行为
  5. Django:测试成功加载静态文件
  6. Appium基于Python APP自动化测试框架
  7. 初学者的Selenium自动化测试指南,基于Python(五)——常用键盘事件
  8. 基于Python的XSS测试工具XSStrike使用方法
  9. 我需要一个django-芹菜守护进程来监听特定的rabbitmq通道

随机推荐

  1. android manifest
  2. android 设置各种颜色 android:backgrou
  3. Using the Android Camera - Android OS
  4. android studio Missing Constraints in
  5. Android CLAT
  6. Android之xml属性
  7. item点击波纹动画
  8. Android SDK 证书没接受问题
  9. shape带边框的背景
  10. Android - Designtime Layout Attributes