forked from celery/django-celery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FAQ
81 lines (57 loc) · 2.46 KB
/
FAQ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
============================
Frequently Asked Questions
============================
Generating a template in a task doesn't seem to respect my i18n settings?
-------------------------------------------------------------------------
**Answer**: To enable the Django translation machinery you need to activate
it with a language. **Note**: Be sure to reset to the previous language when
done.
>>> from django.utils import translation
>>> prev_language = translation.get_language()
>>> translation.activate(language)
>>> try:
... render_template()
... finally:
translation.activate(prev_language)
The common pattern here would be for the task to take a ``language``
argument:
.. code-block:: python
from celery.decorators import task
from django.utils import translation
from django.template.loader import render_to_string
@task()
def generate_report(template="report.html", language=None):
prev_language = translation.get_language()
language and translation.activate(language)
try:
report = render_to_string(template)
finally:
translation.activate(prev_language)
save_report_somewhere(report)
The celery test-suite is failing
--------------------------------
**Answer**: If you're running tests from your Django project, and the celery
test suite is failing in that context, then follow the steps below. If the
celery tests are failing in another context, please report an issue to our
issue tracker at GitHub:
http://github.com/celery/celery/issues/
That Django is running tests for all applications in ``INSTALLED_APPS``
by default is a pet peeve for many. You should use a test runner that either
1) Explicitly lists the apps you want to run tests for, or
2) Make a test runner that skips tests for apps you don't want to run.
For example the test runner that celery is using:
http://github.com/celery/celery/blob/f90491fe0194aa472b5aecdefe5cc83289e65e69/celery/tests/runners.py
To use this test runner, add the following to your ``settings.py``:
.. code-block:: python
TEST_RUNNER = "djcelery.tests.runners.CeleryTestSuiteRunner",
TEST_APPS = (
"app1",
"app2",
"app3",
"app4",
)
Or, if you just want to skip the celery tests:
.. code-block:: python
INSTALLED_APPS = (.....)
TEST_RUNNER = "djcelery.tests.runners.CeleryTestSuiteRunner",
TEST_APPS = filter(lambda k: k != "celery", INSTALLED_APPS)