我有一个celery_test.py文件,它应该加载Django中的测试配置设置(config.test),但它加载的是开发配置(config.development)
from __future__ import absolute_import
import os
from django.conf import settings
from celery import Celery
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "config.testing"
)
test_app = Celery('test')
test_app.config_from_object('django.conf:settings')
test_app.autodiscover_tasks()
print("Testing celery")
print(settings)
@test_app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))当我打印设置时,它打印的是config.development而不是config.testing。有没有人可以教我如何加载config.testing
发布于 2020-01-08 18:45:05
假设您使用的是pytest,您可以将以下内容放入pytest.ini文件中:
[pytest]
DJANGO_SETTINGS_MODULE = celery_test.py或使用:
DJANGO_SETTINGS_MODULE=celery_test.py pytest就是一句小笑话。
https://stackoverflow.com/questions/59642151
复制相似问题