|
@@ -1,12 +1,14 @@
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
|
import gc
|
|
|
-import os
|
|
|
import itertools
|
|
|
+import os
|
|
|
+import pytest
|
|
|
|
|
|
from copy import deepcopy
|
|
|
from pickle import loads, dumps
|
|
|
|
|
|
+from case import ContextMock, Mock, mock, patch
|
|
|
from vine import promise
|
|
|
|
|
|
from celery import Celery
|
|
@@ -16,7 +18,7 @@ from celery import _state
|
|
|
from celery.app import base as _appbase
|
|
|
from celery.app import defaults
|
|
|
from celery.exceptions import ImproperlyConfigured
|
|
|
-from celery.five import keys
|
|
|
+from celery.five import items, keys
|
|
|
from celery.loaders.base import unconfigured
|
|
|
from celery.platforms import pyimplementation
|
|
|
from celery.utils.collections import DictAttribute
|
|
@@ -24,17 +26,6 @@ from celery.utils.serialization import pickle
|
|
|
from celery.utils.time import timezone
|
|
|
from celery.utils.objects import Bunch
|
|
|
|
|
|
-from celery.tests.case import (
|
|
|
- CELERY_TEST_CONFIG,
|
|
|
- AppCase,
|
|
|
- Mock,
|
|
|
- Case,
|
|
|
- ContextMock,
|
|
|
- depends_on_current_app,
|
|
|
- mock,
|
|
|
- patch,
|
|
|
-)
|
|
|
-
|
|
|
THIS_IS_A_KEY = 'this is a value'
|
|
|
|
|
|
|
|
@@ -54,37 +45,32 @@ class ObjectConfig2(object):
|
|
|
UNDERSTAND_ME = True
|
|
|
|
|
|
|
|
|
-def _get_test_config():
|
|
|
- return deepcopy(CELERY_TEST_CONFIG)
|
|
|
-test_config = _get_test_config()
|
|
|
-
|
|
|
-
|
|
|
-class test_module(AppCase):
|
|
|
+class test_module:
|
|
|
|
|
|
def test_default_app(self):
|
|
|
- self.assertEqual(_app.default_app, _state.default_app)
|
|
|
+ assert _app.default_app == _state.default_app
|
|
|
|
|
|
- def test_bugreport(self):
|
|
|
- self.assertTrue(_app.bugreport(app=self.app))
|
|
|
+ def test_bugreport(self, app):
|
|
|
+ assert _app.bugreport(app=app)
|
|
|
|
|
|
|
|
|
-class test_task_join_will_block(Case):
|
|
|
+class test_task_join_will_block:
|
|
|
|
|
|
- def test_task_join_will_block(self):
|
|
|
- prev, _state._task_join_will_block = _state._task_join_will_block, 0
|
|
|
- try:
|
|
|
- self.assertEqual(_state._task_join_will_block, 0)
|
|
|
- _state._set_task_join_will_block(True)
|
|
|
- print(_state.task_join_will_block)
|
|
|
- self.assertTrue(_state.task_join_will_block())
|
|
|
- finally:
|
|
|
- _state._task_join_will_block = prev
|
|
|
+ def test_task_join_will_block(self, patching):
|
|
|
+ patching('celery._state._task_join_will_block', 0)
|
|
|
+ assert _state._task_join_will_block == 0
|
|
|
+ _state._set_task_join_will_block(True)
|
|
|
+ assert _state._task_join_will_block is True
|
|
|
+ # fixture 'app' sets this, so need to use orig_ function
|
|
|
+ # set there by that fixture.
|
|
|
+ res = _state.orig_task_join_will_block()
|
|
|
+ assert res is True
|
|
|
|
|
|
|
|
|
-class test_App(AppCase):
|
|
|
+class test_App:
|
|
|
|
|
|
def setup(self):
|
|
|
- self.app.add_defaults(test_config)
|
|
|
+ self.app.add_defaults(deepcopy(self.CELERY_TEST_CONFIG))
|
|
|
|
|
|
def test_task_autofinalize_disabled(self):
|
|
|
with self.Celery('xyzibari', autofinalize=False) as app:
|
|
@@ -92,7 +78,7 @@ class test_App(AppCase):
|
|
|
def ttafd():
|
|
|
return 42
|
|
|
|
|
|
- with self.assertRaises(RuntimeError):
|
|
|
+ with pytest.raises(RuntimeError):
|
|
|
ttafd()
|
|
|
|
|
|
with self.Celery('xyzibari', autofinalize=False) as app:
|
|
@@ -101,14 +87,14 @@ class test_App(AppCase):
|
|
|
return 42
|
|
|
|
|
|
app.finalize()
|
|
|
- self.assertEqual(ttafd2(), 42)
|
|
|
+ assert ttafd2() == 42
|
|
|
|
|
|
def test_registry_autofinalize_disabled(self):
|
|
|
with self.Celery('xyzibari', autofinalize=False) as app:
|
|
|
- with self.assertRaises(RuntimeError):
|
|
|
+ with pytest.raises(RuntimeError):
|
|
|
app.tasks['celery.chain']
|
|
|
app.finalize()
|
|
|
- self.assertTrue(app.tasks['celery.chain'])
|
|
|
+ assert app.tasks['celery.chain']
|
|
|
|
|
|
def test_task(self):
|
|
|
with self.Celery('foozibari') as app:
|
|
@@ -118,20 +104,20 @@ class test_App(AppCase):
|
|
|
|
|
|
fun.__module__ = '__main__'
|
|
|
task = app.task(fun)
|
|
|
- self.assertEqual(task.name, app.main + '.fun')
|
|
|
+ assert task.name == app.main + '.fun'
|
|
|
|
|
|
def test_task_too_many_args(self):
|
|
|
- with self.assertRaises(TypeError):
|
|
|
+ with pytest.raises(TypeError):
|
|
|
self.app.task(Mock(name='fun'), True)
|
|
|
- with self.assertRaises(TypeError):
|
|
|
+ with pytest.raises(TypeError):
|
|
|
self.app.task(Mock(name='fun'), True, 1, 2)
|
|
|
|
|
|
def test_with_config_source(self):
|
|
|
with self.Celery(config_source=ObjectConfig) as app:
|
|
|
- self.assertEqual(app.conf.FOO, 1)
|
|
|
- self.assertEqual(app.conf.BAR, 2)
|
|
|
+ assert app.conf.FOO == 1
|
|
|
+ assert app.conf.BAR == 2
|
|
|
|
|
|
- @depends_on_current_app
|
|
|
+ @pytest.mark.usefixtures('depends_on_current_app')
|
|
|
def test_task_windows_execv(self):
|
|
|
prev, _appbase.USING_EXECV = _appbase.USING_EXECV, True
|
|
|
try:
|
|
@@ -139,55 +125,55 @@ class test_App(AppCase):
|
|
|
def foo():
|
|
|
pass
|
|
|
|
|
|
- self.assertTrue(foo._get_current_object()) # is proxy
|
|
|
+ assert foo._get_current_object() # is proxy
|
|
|
|
|
|
finally:
|
|
|
_appbase.USING_EXECV = prev
|
|
|
assert not _appbase.USING_EXECV
|
|
|
|
|
|
def test_task_takes_no_args(self):
|
|
|
- with self.assertRaises(TypeError):
|
|
|
+ with pytest.raises(TypeError):
|
|
|
@self.app.task(1)
|
|
|
def foo():
|
|
|
pass
|
|
|
|
|
|
def test_add_defaults(self):
|
|
|
- self.assertFalse(self.app.configured)
|
|
|
+ assert not self.app.configured
|
|
|
_conf = {'FOO': 300}
|
|
|
|
|
|
def conf():
|
|
|
return _conf
|
|
|
|
|
|
self.app.add_defaults(conf)
|
|
|
- self.assertIn(conf, self.app._pending_defaults)
|
|
|
- self.assertFalse(self.app.configured)
|
|
|
- self.assertEqual(self.app.conf.FOO, 300)
|
|
|
- self.assertTrue(self.app.configured)
|
|
|
- self.assertFalse(self.app._pending_defaults)
|
|
|
+ assert conf in self.app._pending_defaults
|
|
|
+ assert not self.app.configured
|
|
|
+ assert self.app.conf.FOO == 300
|
|
|
+ assert self.app.configured
|
|
|
+ assert not self.app._pending_defaults
|
|
|
|
|
|
# defaults not pickled
|
|
|
appr = loads(dumps(self.app))
|
|
|
- with self.assertRaises(AttributeError):
|
|
|
+ with pytest.raises(AttributeError):
|
|
|
appr.conf.FOO
|
|
|
|
|
|
# add more defaults after configured
|
|
|
conf2 = {'FOO': 'BAR'}
|
|
|
self.app.add_defaults(conf2)
|
|
|
- self.assertEqual(self.app.conf.FOO, 'BAR')
|
|
|
+ assert self.app.conf.FOO == 'BAR'
|
|
|
|
|
|
- self.assertIn(_conf, self.app.conf.defaults)
|
|
|
- self.assertIn(conf2, self.app.conf.defaults)
|
|
|
+ assert _conf in self.app.conf.defaults
|
|
|
+ assert conf2 in self.app.conf.defaults
|
|
|
|
|
|
def test_connection_or_acquire(self):
|
|
|
with self.app.connection_or_acquire(block=True):
|
|
|
- self.assertTrue(self.app.pool._dirty)
|
|
|
+ assert self.app.pool._dirty
|
|
|
|
|
|
with self.app.connection_or_acquire(pool=False):
|
|
|
- self.assertFalse(self.app.pool._dirty)
|
|
|
+ assert not self.app.pool._dirty
|
|
|
|
|
|
def test_using_v1_reduce(self):
|
|
|
self.app._using_v1_reduce = True
|
|
|
- self.assertTrue(loads(dumps(self.app)))
|
|
|
+ assert loads(dumps(self.app))
|
|
|
|
|
|
def test_autodiscover_tasks_force(self):
|
|
|
self.app.loader.autodiscover_tasks = Mock()
|
|
@@ -215,9 +201,9 @@ class test_App(AppCase):
|
|
|
self.app.autodiscover_tasks(lazy_list)
|
|
|
import_modules.connect.assert_called()
|
|
|
prom = import_modules.connect.call_args[0][0]
|
|
|
- self.assertIsInstance(prom, promise)
|
|
|
- self.assertEqual(prom.fun, self.app._autodiscover_tasks)
|
|
|
- self.assertEqual(prom.args[0](), [1, 2, 3])
|
|
|
+ assert isinstance(prom, promise)
|
|
|
+ assert prom.fun == self.app._autodiscover_tasks
|
|
|
+ assert prom.args[0](), [1, 2 == 3]
|
|
|
|
|
|
def test_autodiscover_tasks__no_packages(self):
|
|
|
fixup1 = Mock(name='fixup')
|
|
@@ -231,28 +217,28 @@ class test_App(AppCase):
|
|
|
['A', 'B', 'C', 'D', 'E', 'F'], related_name='tasks',
|
|
|
)
|
|
|
|
|
|
- @mock.environ('CELERY_BROKER_URL', '')
|
|
|
- def test_with_broker(self):
|
|
|
+ def test_with_broker(self, patching):
|
|
|
+ patching.setenv('CELERY_BROKER_URL', '')
|
|
|
with self.Celery(broker='foo://baribaz') as app:
|
|
|
- self.assertEqual(app.conf.broker_url, 'foo://baribaz')
|
|
|
+ assert app.conf.broker_url == 'foo://baribaz'
|
|
|
|
|
|
def test_pending_configuration__setattr(self):
|
|
|
with self.Celery(broker='foo://bar') as app:
|
|
|
app.conf.task_default_delivery_mode = 44
|
|
|
app.conf.worker_agent = 'foo:Bar'
|
|
|
- self.assertFalse(app.configured)
|
|
|
- self.assertEqual(app.conf.worker_agent, 'foo:Bar')
|
|
|
- self.assertEqual(app.conf.broker_url, 'foo://bar')
|
|
|
- self.assertEqual(app._preconf['worker_agent'], 'foo:Bar')
|
|
|
+ assert not app.configured
|
|
|
+ assert app.conf.worker_agent == 'foo:Bar'
|
|
|
+ assert app.conf.broker_url == 'foo://bar'
|
|
|
+ assert app._preconf['worker_agent'] == 'foo:Bar'
|
|
|
|
|
|
- self.assertTrue(app.configured)
|
|
|
+ assert app.configured
|
|
|
reapp = pickle.loads(pickle.dumps(app))
|
|
|
- self.assertEqual(reapp._preconf['worker_agent'], 'foo:Bar')
|
|
|
- self.assertFalse(reapp.configured)
|
|
|
- self.assertEqual(reapp.conf.worker_agent, 'foo:Bar')
|
|
|
- self.assertTrue(reapp.configured)
|
|
|
- self.assertEqual(reapp.conf.broker_url, 'foo://bar')
|
|
|
- self.assertEqual(reapp._preconf['worker_agent'], 'foo:Bar')
|
|
|
+ assert reapp._preconf['worker_agent'] == 'foo:Bar'
|
|
|
+ assert not reapp.configured
|
|
|
+ assert reapp.conf.worker_agent == 'foo:Bar'
|
|
|
+ assert reapp.configured
|
|
|
+ assert reapp.conf.broker_url == 'foo://bar'
|
|
|
+ assert reapp._preconf['worker_agent'] == 'foo:Bar'
|
|
|
|
|
|
def test_pending_configuration__update(self):
|
|
|
with self.Celery(broker='foo://bar') as app:
|
|
@@ -260,10 +246,10 @@ class test_App(AppCase):
|
|
|
task_default_delivery_mode=44,
|
|
|
worker_agent='foo:Bar',
|
|
|
)
|
|
|
- self.assertFalse(app.configured)
|
|
|
- self.assertEqual(app.conf.worker_agent, 'foo:Bar')
|
|
|
- self.assertEqual(app.conf.broker_url, 'foo://bar')
|
|
|
- self.assertEqual(app._preconf['worker_agent'], 'foo:Bar')
|
|
|
+ assert not app.configured
|
|
|
+ assert app.conf.worker_agent == 'foo:Bar'
|
|
|
+ assert app.conf.broker_url == 'foo://bar'
|
|
|
+ assert app._preconf['worker_agent'] == 'foo:Bar'
|
|
|
|
|
|
def test_pending_configuration__compat_settings(self):
|
|
|
with self.Celery(broker='foo://bar', backend='foo') as app:
|
|
@@ -272,11 +258,11 @@ class test_App(AppCase):
|
|
|
CELERY_DEFAULT_DELIVERY_MODE=63,
|
|
|
CELERYD_AGENT='foo:Barz',
|
|
|
)
|
|
|
- self.assertEqual(app.conf.task_always_eager, 4)
|
|
|
- self.assertEqual(app.conf.task_default_delivery_mode, 63)
|
|
|
- self.assertEqual(app.conf.worker_agent, 'foo:Barz')
|
|
|
- self.assertEqual(app.conf.broker_url, 'foo://bar')
|
|
|
- self.assertEqual(app.conf.result_backend, 'foo')
|
|
|
+ assert app.conf.task_always_eager == 4
|
|
|
+ assert app.conf.task_default_delivery_mode == 63
|
|
|
+ assert app.conf.worker_agent == 'foo:Barz'
|
|
|
+ assert app.conf.broker_url == 'foo://bar'
|
|
|
+ assert app.conf.result_backend == 'foo'
|
|
|
|
|
|
def test_pending_configuration__compat_settings_mixing(self):
|
|
|
with self.Celery(broker='foo://bar', backend='foo') as app:
|
|
@@ -286,8 +272,8 @@ class test_App(AppCase):
|
|
|
CELERYD_AGENT='foo:Barz',
|
|
|
worker_consumer='foo:Fooz',
|
|
|
)
|
|
|
- with self.assertRaises(ImproperlyConfigured):
|
|
|
- self.assertEqual(app.conf.task_always_eager, 4)
|
|
|
+ with pytest.raises(ImproperlyConfigured):
|
|
|
+ assert app.conf.task_always_eager == 4
|
|
|
|
|
|
def test_pending_configuration__django_settings(self):
|
|
|
with self.Celery(broker='foo://bar', backend='foo') as app:
|
|
@@ -297,13 +283,13 @@ class test_App(AppCase):
|
|
|
CELERY_WORKER_AGENT='foo:Barz',
|
|
|
CELERY_RESULT_SERIALIZER='pickle',
|
|
|
)), namespace='CELERY')
|
|
|
- self.assertEqual(app.conf.result_serializer, 'pickle')
|
|
|
- self.assertEqual(app.conf.CELERY_RESULT_SERIALIZER, 'pickle')
|
|
|
- self.assertEqual(app.conf.task_always_eager, 4)
|
|
|
- self.assertEqual(app.conf.task_default_delivery_mode, 63)
|
|
|
- self.assertEqual(app.conf.worker_agent, 'foo:Barz')
|
|
|
- self.assertEqual(app.conf.broker_url, 'foo://bar')
|
|
|
- self.assertEqual(app.conf.result_backend, 'foo')
|
|
|
+ assert app.conf.result_serializer == 'pickle'
|
|
|
+ assert app.conf.CELERY_RESULT_SERIALIZER == 'pickle'
|
|
|
+ assert app.conf.task_always_eager == 4
|
|
|
+ assert app.conf.task_default_delivery_mode == 63
|
|
|
+ assert app.conf.worker_agent == 'foo:Barz'
|
|
|
+ assert app.conf.broker_url == 'foo://bar'
|
|
|
+ assert app.conf.result_backend == 'foo'
|
|
|
|
|
|
def test_pending_configuration__compat_settings_mixing_new(self):
|
|
|
with self.Celery(broker='foo://bar', backend='foo') as app:
|
|
@@ -314,8 +300,8 @@ class test_App(AppCase):
|
|
|
CELERYD_CONSUMER='foo:Fooz',
|
|
|
CELERYD_POOL='foo:Xuzzy',
|
|
|
)
|
|
|
- with self.assertRaises(ImproperlyConfigured):
|
|
|
- self.assertEqual(app.conf.worker_consumer, 'foo:Fooz')
|
|
|
+ with pytest.raises(ImproperlyConfigured):
|
|
|
+ assert app.conf.worker_consumer == 'foo:Fooz'
|
|
|
|
|
|
def test_pending_configuration__compat_settings_mixing_alt(self):
|
|
|
with self.Celery(broker='foo://bar', backend='foo') as app:
|
|
@@ -328,52 +314,52 @@ class test_App(AppCase):
|
|
|
CELERYD_POOL='foo:Xuzzy',
|
|
|
worker_pool='foo:Xuzzy'
|
|
|
)
|
|
|
- self.assertEqual(app.conf.task_always_eager, 4)
|
|
|
- self.assertEqual(app.conf.worker_pool, 'foo:Xuzzy')
|
|
|
+ assert app.conf.task_always_eager == 4
|
|
|
+ assert app.conf.worker_pool == 'foo:Xuzzy'
|
|
|
|
|
|
def test_pending_configuration__setdefault(self):
|
|
|
with self.Celery(broker='foo://bar') as app:
|
|
|
app.conf.setdefault('worker_agent', 'foo:Bar')
|
|
|
- self.assertFalse(app.configured)
|
|
|
+ assert not app.configured
|
|
|
|
|
|
def test_pending_configuration__iter(self):
|
|
|
with self.Celery(broker='foo://bar') as app:
|
|
|
app.conf.worker_agent = 'foo:Bar'
|
|
|
- self.assertFalse(app.configured)
|
|
|
- self.assertTrue(list(keys(app.conf)))
|
|
|
- self.assertFalse(app.configured)
|
|
|
- self.assertIn('worker_agent', app.conf)
|
|
|
- self.assertFalse(app.configured)
|
|
|
- self.assertTrue(dict(app.conf))
|
|
|
- self.assertTrue(app.configured)
|
|
|
+ assert not app.configured
|
|
|
+ assert list(keys(app.conf))
|
|
|
+ assert not app.configured
|
|
|
+ assert 'worker_agent' in app.conf
|
|
|
+ assert not app.configured
|
|
|
+ assert dict(app.conf)
|
|
|
+ assert app.configured
|
|
|
|
|
|
def test_pending_configuration__raises_ImproperlyConfigured(self):
|
|
|
with self.Celery(set_as_current=False) as app:
|
|
|
app.conf.worker_agent = 'foo://bar'
|
|
|
app.conf.task_default_delivery_mode = 44
|
|
|
app.conf.CELERY_ALWAYS_EAGER = 5
|
|
|
- with self.assertRaises(ImproperlyConfigured):
|
|
|
+ with pytest.raises(ImproperlyConfigured):
|
|
|
app.finalize()
|
|
|
|
|
|
with self.Celery() as app:
|
|
|
- self.assertFalse(self.app.conf.task_always_eager)
|
|
|
+ assert not self.app.conf.task_always_eager
|
|
|
|
|
|
def test_repr(self):
|
|
|
- self.assertTrue(repr(self.app))
|
|
|
+ assert repr(self.app)
|
|
|
|
|
|
def test_custom_task_registry(self):
|
|
|
with self.Celery(tasks=self.app.tasks) as app2:
|
|
|
- self.assertIs(app2.tasks, self.app.tasks)
|
|
|
+ assert app2.tasks is self.app.tasks
|
|
|
|
|
|
def test_include_argument(self):
|
|
|
with self.Celery(include=('foo', 'bar.foo')) as app:
|
|
|
- self.assertEqual(app.conf.include, ('foo', 'bar.foo'))
|
|
|
+ assert app.conf.include, ('foo' == 'bar.foo')
|
|
|
|
|
|
def test_set_as_current(self):
|
|
|
current = _state._tls.current_app
|
|
|
try:
|
|
|
app = self.Celery(set_as_current=True)
|
|
|
- self.assertIs(_state._tls.current_app, app)
|
|
|
+ assert _state._tls.current_app is app
|
|
|
finally:
|
|
|
_state._tls.current_app = current
|
|
|
|
|
@@ -384,7 +370,7 @@ class test_App(AppCase):
|
|
|
|
|
|
_state._task_stack.push(foo)
|
|
|
try:
|
|
|
- self.assertEqual(self.app.current_task.name, foo.name)
|
|
|
+ assert self.app.current_task.name == foo.name
|
|
|
finally:
|
|
|
_state._task_stack.pop()
|
|
|
|
|
@@ -433,7 +419,7 @@ class test_App(AppCase):
|
|
|
def foo():
|
|
|
pass
|
|
|
|
|
|
- self.assertEqual(foo.name, 'xuzzy.foo')
|
|
|
+ assert foo.name == 'xuzzy.foo'
|
|
|
finally:
|
|
|
_imports.MP_MAIN_FILE = None
|
|
|
|
|
@@ -458,7 +444,7 @@ class test_App(AppCase):
|
|
|
adX.name: {'@__call__': deco}
|
|
|
}
|
|
|
adX.bind(self.app)
|
|
|
- self.assertIs(adX.app, self.app)
|
|
|
+ assert adX.app is self.app
|
|
|
|
|
|
i = adX()
|
|
|
i(2, 4, x=3)
|
|
@@ -472,9 +458,9 @@ class test_App(AppCase):
|
|
|
def aawsX(x, y):
|
|
|
pass
|
|
|
|
|
|
- with self.assertRaises(TypeError):
|
|
|
+ with pytest.raises(TypeError):
|
|
|
aawsX.apply_async(())
|
|
|
- with self.assertRaises(TypeError):
|
|
|
+ with pytest.raises(TypeError):
|
|
|
aawsX.apply_async((2,))
|
|
|
|
|
|
with patch('celery.app.amqp.AMQP.create_task_message') as create:
|
|
@@ -482,7 +468,7 @@ class test_App(AppCase):
|
|
|
create.return_value = Mock(), Mock(), Mock(), Mock()
|
|
|
aawsX.apply_async((4, 5))
|
|
|
args = create.call_args[0][2]
|
|
|
- self.assertEqual(args, ('hello', 4, 5))
|
|
|
+ assert args, ('hello', 4 == 5)
|
|
|
send.assert_called()
|
|
|
|
|
|
def test_apply_async_adds_children(self):
|
|
@@ -501,7 +487,7 @@ class test_App(AppCase):
|
|
|
a3cX1.push_request(called_directly=False)
|
|
|
try:
|
|
|
res = a3cX2.apply_async(add_to_parent=True)
|
|
|
- self.assertIn(res, a3cX1.request.children)
|
|
|
+ assert res in a3cX1.request.children
|
|
|
finally:
|
|
|
a3cX1.pop_request()
|
|
|
finally:
|
|
@@ -512,9 +498,10 @@ class test_App(AppCase):
|
|
|
THE_MII_MAR='jars')
|
|
|
self.app.conf.update(changes)
|
|
|
saved = pickle.dumps(self.app)
|
|
|
- self.assertLess(len(saved), 2048)
|
|
|
+ assert len(saved) < 2048
|
|
|
restored = pickle.loads(saved)
|
|
|
- self.assertDictContainsSubset(changes, restored.conf)
|
|
|
+ for key, value in items(changes):
|
|
|
+ assert restored.conf[key] == value
|
|
|
|
|
|
def test_worker_main(self):
|
|
|
from celery.bin import worker as worker_bin
|
|
@@ -527,33 +514,33 @@ class test_App(AppCase):
|
|
|
prev, worker_bin.worker = worker_bin.worker, worker
|
|
|
try:
|
|
|
ret = self.app.worker_main(argv=['--version'])
|
|
|
- self.assertListEqual(ret, ['--version'])
|
|
|
+ assert ret == ['--version']
|
|
|
finally:
|
|
|
worker_bin.worker = prev
|
|
|
|
|
|
def test_config_from_envvar(self):
|
|
|
- os.environ['CELERYTEST_CONFIG_OBJECT'] = 'celery.tests.app.test_app'
|
|
|
+ os.environ['CELERYTEST_CONFIG_OBJECT'] = 't.unit.app.test_app'
|
|
|
self.app.config_from_envvar('CELERYTEST_CONFIG_OBJECT')
|
|
|
- self.assertEqual(self.app.conf.THIS_IS_A_KEY, 'this is a value')
|
|
|
+ assert self.app.conf.THIS_IS_A_KEY == 'this is a value'
|
|
|
|
|
|
def assert_config2(self):
|
|
|
- self.assertTrue(self.app.conf.LEAVE_FOR_WORK)
|
|
|
- self.assertTrue(self.app.conf.MOMENT_TO_STOP)
|
|
|
- self.assertEqual(self.app.conf.CALL_ME_BACK, 123456789)
|
|
|
- self.assertFalse(self.app.conf.WANT_ME_TO)
|
|
|
- self.assertTrue(self.app.conf.UNDERSTAND_ME)
|
|
|
+ assert self.app.conf.LEAVE_FOR_WORK
|
|
|
+ assert self.app.conf.MOMENT_TO_STOP
|
|
|
+ assert self.app.conf.CALL_ME_BACK == 123456789
|
|
|
+ assert not self.app.conf.WANT_ME_TO
|
|
|
+ assert self.app.conf.UNDERSTAND_ME
|
|
|
|
|
|
def test_config_from_object__lazy(self):
|
|
|
conf = ObjectConfig2()
|
|
|
self.app.config_from_object(conf)
|
|
|
- self.assertIs(self.app.loader._conf, unconfigured)
|
|
|
- self.assertIs(self.app._config_source, conf)
|
|
|
+ assert self.app.loader._conf is unconfigured
|
|
|
+ assert self.app._config_source is conf
|
|
|
|
|
|
self.assert_config2()
|
|
|
|
|
|
def test_config_from_object__force(self):
|
|
|
self.app.config_from_object(ObjectConfig2(), force=True)
|
|
|
- self.assertTrue(self.app.loader._conf)
|
|
|
+ assert self.app.loader._conf
|
|
|
|
|
|
self.assert_config2()
|
|
|
|
|
@@ -565,10 +552,10 @@ class test_App(AppCase):
|
|
|
CELERY_TASK_PUBLISH_RETRY = False
|
|
|
|
|
|
self.app.config_from_object(Config)
|
|
|
- self.assertEqual(self.app.conf.task_always_eager, 44)
|
|
|
- self.assertEqual(self.app.conf.CELERY_ALWAYS_EAGER, 44)
|
|
|
- self.assertFalse(self.app.conf.task_publish_retry)
|
|
|
- self.assertEqual(self.app.conf.task_default_routing_key, 'testcelery')
|
|
|
+ assert self.app.conf.task_always_eager == 44
|
|
|
+ assert self.app.conf.CELERY_ALWAYS_EAGER == 44
|
|
|
+ assert not self.app.conf.task_publish_retry
|
|
|
+ assert self.app.conf.task_default_routing_key == 'testcelery'
|
|
|
|
|
|
def test_config_from_object__supports_old_names(self):
|
|
|
|
|
@@ -577,11 +564,11 @@ class test_App(AppCase):
|
|
|
task_default_delivery_mode = 301
|
|
|
|
|
|
self.app.config_from_object(Config())
|
|
|
- self.assertEqual(self.app.conf.CELERY_ALWAYS_EAGER, 45)
|
|
|
- self.assertEqual(self.app.conf.task_always_eager, 45)
|
|
|
- self.assertEqual(self.app.conf.CELERY_DEFAULT_DELIVERY_MODE, 301)
|
|
|
- self.assertEqual(self.app.conf.task_default_delivery_mode, 301)
|
|
|
- self.assertEqual(self.app.conf.task_default_routing_key, 'testcelery')
|
|
|
+ assert self.app.conf.CELERY_ALWAYS_EAGER == 45
|
|
|
+ assert self.app.conf.task_always_eager == 45
|
|
|
+ assert self.app.conf.CELERY_DEFAULT_DELIVERY_MODE == 301
|
|
|
+ assert self.app.conf.task_default_delivery_mode == 301
|
|
|
+ assert self.app.conf.task_default_routing_key == 'testcelery'
|
|
|
|
|
|
def test_config_from_object__namespace_uppercase(self):
|
|
|
|
|
@@ -590,7 +577,7 @@ class test_App(AppCase):
|
|
|
CELERY_TASK_DEFAULT_DELIVERY_MODE = 301
|
|
|
|
|
|
self.app.config_from_object(Config(), namespace='CELERY')
|
|
|
- self.assertEqual(self.app.conf.task_always_eager, 44)
|
|
|
+ assert self.app.conf.task_always_eager == 44
|
|
|
|
|
|
def test_config_from_object__namespace_lowercase(self):
|
|
|
|
|
@@ -599,7 +586,7 @@ class test_App(AppCase):
|
|
|
celery_task_default_delivery_mode = 301
|
|
|
|
|
|
self.app.config_from_object(Config(), namespace='celery')
|
|
|
- self.assertEqual(self.app.conf.task_always_eager, 44)
|
|
|
+ assert self.app.conf.task_always_eager == 44
|
|
|
|
|
|
def test_config_from_object__mixing_new_and_old(self):
|
|
|
|
|
@@ -610,11 +597,10 @@ class test_App(AppCase):
|
|
|
beat_schedule = '/foo/schedule'
|
|
|
CELERY_DEFAULT_DELIVERY_MODE = 301
|
|
|
|
|
|
- with self.assertRaises(ImproperlyConfigured) as exc:
|
|
|
+ with pytest.raises(ImproperlyConfigured) as exc:
|
|
|
self.app.config_from_object(Config(), force=True)
|
|
|
- self.assertTrue(
|
|
|
- exc.args[0].startswith('CELERY_DEFAULT_DELIVERY_MODE'))
|
|
|
- self.assertIn('task_default_delivery_mode', exc.args[0])
|
|
|
+ assert exc.args[0].startswith('CELERY_DEFAULT_DELIVERY_MODE')
|
|
|
+ assert 'task_default_delivery_mode' in exc.args[0]
|
|
|
|
|
|
def test_config_from_object__mixing_old_and_new(self):
|
|
|
|
|
@@ -625,11 +611,10 @@ class test_App(AppCase):
|
|
|
CELERYBEAT_SCHEDULE = '/foo/schedule'
|
|
|
task_default_delivery_mode = 301
|
|
|
|
|
|
- with self.assertRaises(ImproperlyConfigured) as exc:
|
|
|
+ with pytest.raises(ImproperlyConfigured) as exc:
|
|
|
self.app.config_from_object(Config(), force=True)
|
|
|
- self.assertTrue(
|
|
|
- exc.args[0].startswith('task_default_delivery_mode'))
|
|
|
- self.assertIn('CELERY_DEFAULT_DELIVERY_MODE', exc.args[0])
|
|
|
+ assert exc.args[0].startswith('task_default_delivery_mode')
|
|
|
+ assert 'CELERY_DEFAULT_DELIVERY_MODE' in exc.args[0]
|
|
|
|
|
|
def test_config_from_cmdline(self):
|
|
|
cmdline = ['task_always_eager=no',
|
|
@@ -639,139 +624,130 @@ class test_App(AppCase):
|
|
|
'.foobarint=(int)300',
|
|
|
'sqlalchemy_engine_options=(dict){"foo": "bar"}']
|
|
|
self.app.config_from_cmdline(cmdline, namespace='worker')
|
|
|
- self.assertFalse(self.app.conf.task_always_eager)
|
|
|
- self.assertEqual(self.app.conf.result_backend, '/dev/null')
|
|
|
- self.assertEqual(self.app.conf.worker_prefetch_multiplier, 368)
|
|
|
- self.assertEqual(self.app.conf.worker_foobarstring, '300')
|
|
|
- self.assertEqual(self.app.conf.worker_foobarint, 300)
|
|
|
- self.assertDictEqual(self.app.conf.sqlalchemy_engine_options,
|
|
|
- {'foo': 'bar'})
|
|
|
+ assert not self.app.conf.task_always_eager
|
|
|
+ assert self.app.conf.result_backend == '/dev/null'
|
|
|
+ assert self.app.conf.worker_prefetch_multiplier == 368
|
|
|
+ assert self.app.conf.worker_foobarstring == '300'
|
|
|
+ assert self.app.conf.worker_foobarint == 300
|
|
|
+ assert self.app.conf.sqlalchemy_engine_options == {'foo': 'bar'}
|
|
|
|
|
|
def test_setting__broker_transport_options(self):
|
|
|
|
|
|
_args = {'foo': 'bar', 'spam': 'baz'}
|
|
|
|
|
|
self.app.config_from_object(Bunch())
|
|
|
- self.assertEqual(self.app.conf.broker_transport_options, {})
|
|
|
+ assert self.app.conf.broker_transport_options == {}
|
|
|
|
|
|
self.app.config_from_object(Bunch(broker_transport_options=_args))
|
|
|
- self.assertEqual(self.app.conf.broker_transport_options, _args)
|
|
|
+ assert self.app.conf.broker_transport_options == _args
|
|
|
|
|
|
def test_Windows_log_color_disabled(self):
|
|
|
self.app.IS_WINDOWS = True
|
|
|
- self.assertFalse(self.app.log.supports_color(True))
|
|
|
+ assert not self.app.log.supports_color(True)
|
|
|
|
|
|
def test_WorkController(self):
|
|
|
x = self.app.WorkController
|
|
|
- self.assertIs(x.app, self.app)
|
|
|
+ assert x.app is self.app
|
|
|
|
|
|
def test_Worker(self):
|
|
|
x = self.app.Worker
|
|
|
- self.assertIs(x.app, self.app)
|
|
|
+ assert x.app is self.app
|
|
|
|
|
|
- @depends_on_current_app
|
|
|
+ @pytest.mark.usefixtures('depends_on_current_app')
|
|
|
def test_AsyncResult(self):
|
|
|
x = self.app.AsyncResult('1')
|
|
|
- self.assertIs(x.app, self.app)
|
|
|
+ assert x.app is self.app
|
|
|
r = loads(dumps(x))
|
|
|
# not set as current, so ends up as default app after reduce
|
|
|
- self.assertIs(r.app, current_app._get_current_object())
|
|
|
+ assert r.app is current_app._get_current_object()
|
|
|
|
|
|
def test_get_active_apps(self):
|
|
|
- self.assertTrue(list(_state._get_active_apps()))
|
|
|
+ assert list(_state._get_active_apps())
|
|
|
|
|
|
app1 = self.Celery()
|
|
|
appid = id(app1)
|
|
|
- self.assertIn(app1, _state._get_active_apps())
|
|
|
+ assert app1 in _state._get_active_apps()
|
|
|
app1.close()
|
|
|
del(app1)
|
|
|
|
|
|
gc.collect()
|
|
|
|
|
|
# weakref removed from list when app goes out of scope.
|
|
|
- with self.assertRaises(StopIteration):
|
|
|
+ with pytest.raises(StopIteration):
|
|
|
next(app for app in _state._get_active_apps() if id(app) == appid)
|
|
|
|
|
|
def test_config_from_envvar_more(self, key='CELERY_HARNESS_CFG1'):
|
|
|
- self.assertFalse(
|
|
|
- self.app.config_from_envvar(
|
|
|
- 'HDSAJIHWIQHEWQU', force=True, silent=True),
|
|
|
- )
|
|
|
- with self.assertRaises(ImproperlyConfigured):
|
|
|
+ assert not self.app.config_from_envvar(
|
|
|
+ 'HDSAJIHWIQHEWQU', force=True, silent=True)
|
|
|
+ with pytest.raises(ImproperlyConfigured):
|
|
|
self.app.config_from_envvar(
|
|
|
'HDSAJIHWIQHEWQU', force=True, silent=False,
|
|
|
)
|
|
|
os.environ[key] = __name__ + '.object_config'
|
|
|
- self.assertTrue(self.app.config_from_envvar(key, force=True))
|
|
|
- self.assertEqual(self.app.conf['FOO'], 1)
|
|
|
- self.assertEqual(self.app.conf['BAR'], 2)
|
|
|
+ assert self.app.config_from_envvar(key, force=True)
|
|
|
+ assert self.app.conf['FOO'] == 1
|
|
|
+ assert self.app.conf['BAR'] == 2
|
|
|
|
|
|
os.environ[key] = 'unknown_asdwqe.asdwqewqe'
|
|
|
- with self.assertRaises(ImportError):
|
|
|
+ with pytest.raises(ImportError):
|
|
|
self.app.config_from_envvar(key, silent=False)
|
|
|
- self.assertFalse(
|
|
|
- self.app.config_from_envvar(key, force=True, silent=True),
|
|
|
- )
|
|
|
+ assert not self.app.config_from_envvar(key, force=True, silent=True)
|
|
|
|
|
|
os.environ[key] = __name__ + '.dict_config'
|
|
|
- self.assertTrue(self.app.config_from_envvar(key, force=True))
|
|
|
- self.assertEqual(self.app.conf['FOO'], 10)
|
|
|
- self.assertEqual(self.app.conf['BAR'], 20)
|
|
|
+ assert self.app.config_from_envvar(key, force=True)
|
|
|
+ assert self.app.conf['FOO'] == 10
|
|
|
+ assert self.app.conf['BAR'] == 20
|
|
|
|
|
|
@patch('celery.bin.celery.CeleryCommand.execute_from_commandline')
|
|
|
def test_start(self, execute):
|
|
|
self.app.start()
|
|
|
execute.assert_called()
|
|
|
|
|
|
- def test_amqp_get_broker_info(self):
|
|
|
- self.assertDictContainsSubset(
|
|
|
- {'hostname': 'localhost',
|
|
|
- 'userid': 'guest',
|
|
|
- 'password': 'guest',
|
|
|
- 'virtual_host': '/'},
|
|
|
- self.app.connection('pyamqp://').info(),
|
|
|
- )
|
|
|
- self.app.conf.broker_port = 1978
|
|
|
- self.app.conf.broker_vhost = 'foo'
|
|
|
- self.assertDictContainsSubset(
|
|
|
- {'port': 1978, 'virtual_host': 'foo'},
|
|
|
- self.app.connection('pyamqp://:1978/foo').info(),
|
|
|
- )
|
|
|
- conn = self.app.connection('pyamqp:////value')
|
|
|
- self.assertDictContainsSubset({'virtual_host': '/value'},
|
|
|
- conn.info())
|
|
|
+ @pytest.mark.parametrize('url,expected_fields', [
|
|
|
+ ('pyamqp://', {
|
|
|
+ 'hostname': 'localhost',
|
|
|
+ 'userid': 'guest',
|
|
|
+ 'password': 'guest',
|
|
|
+ 'virtual_host': '/',
|
|
|
+ }),
|
|
|
+ ('pyamqp://:1978/foo', {
|
|
|
+ 'port': 1978,
|
|
|
+ 'virtual_host': 'foo',
|
|
|
+ }),
|
|
|
+ ('pyamqp:////value', {
|
|
|
+ 'virtual_host': '/value',
|
|
|
+ })
|
|
|
+ ])
|
|
|
+ def test_amqp_get_broker_info(self, url, expected_fields):
|
|
|
+ info = self.app.connection(url).info()
|
|
|
+ for key, expected_value in items(expected_fields):
|
|
|
+ assert info[key] == expected_value
|
|
|
|
|
|
def test_amqp_failover_strategy_selection(self):
|
|
|
# Test passing in a string and make sure the string
|
|
|
# gets there untouched
|
|
|
self.app.conf.broker_failover_strategy = 'foo-bar'
|
|
|
- self.assertEqual(
|
|
|
- self.app.connection('amqp:////value').failover_strategy,
|
|
|
- 'foo-bar',
|
|
|
- )
|
|
|
+ assert self.app.connection('amqp:////value') \
|
|
|
+ .failover_strategy == 'foo-bar'
|
|
|
|
|
|
# Try passing in None
|
|
|
self.app.conf.broker_failover_strategy = None
|
|
|
- self.assertEqual(
|
|
|
- self.app.connection('amqp:////value').failover_strategy,
|
|
|
- itertools.cycle,
|
|
|
- )
|
|
|
+ assert self.app.connection('amqp:////value') \
|
|
|
+ .failover_strategy == itertools.cycle
|
|
|
|
|
|
# Test passing in a method
|
|
|
def my_failover_strategy(it):
|
|
|
yield True
|
|
|
|
|
|
self.app.conf.broker_failover_strategy = my_failover_strategy
|
|
|
- self.assertEqual(
|
|
|
- self.app.connection('amqp:////value').failover_strategy,
|
|
|
- my_failover_strategy,
|
|
|
- )
|
|
|
+ assert self.app.connection('amqp:////value') \
|
|
|
+ .failover_strategy == my_failover_strategy
|
|
|
|
|
|
def test_after_fork(self):
|
|
|
self.app._pool = Mock()
|
|
|
self.app.on_after_fork = Mock(name='on_after_fork')
|
|
|
self.app._after_fork()
|
|
|
- self.assertIsNone(self.app._pool)
|
|
|
+ assert self.app._pool is None
|
|
|
self.app.on_after_fork.send.assert_called_with(sender=self.app)
|
|
|
self.app._after_fork()
|
|
|
|
|
@@ -794,21 +770,21 @@ class test_App(AppCase):
|
|
|
try:
|
|
|
self.app._after_fork_registered = False
|
|
|
self.app._ensure_after_fork()
|
|
|
- self.assertTrue(self.app._after_fork_registered)
|
|
|
+ assert self.app._after_fork_registered
|
|
|
finally:
|
|
|
_appbase.register_after_fork = prev
|
|
|
|
|
|
def test_canvas(self):
|
|
|
- self.assertTrue(self.app.canvas.Signature)
|
|
|
+ assert self.app.canvas.Signature
|
|
|
|
|
|
def test_signature(self):
|
|
|
sig = self.app.signature('foo', (1, 2))
|
|
|
- self.assertIs(sig.app, self.app)
|
|
|
+ assert sig.app is self.app
|
|
|
|
|
|
def test_timezone__none_set(self):
|
|
|
self.app.conf.timezone = None
|
|
|
tz = self.app.timezone
|
|
|
- self.assertEqual(tz, timezone.get_timezone('UTC'))
|
|
|
+ assert tz == timezone.get_timezone('UTC')
|
|
|
|
|
|
def test_compat_on_configure(self):
|
|
|
_on_configure = Mock(name='on_configure')
|
|
@@ -837,22 +813,22 @@ class test_App(AppCase):
|
|
|
10, self.app.signature('add', (2, 2)),
|
|
|
name='add1', expires=3,
|
|
|
)
|
|
|
- self.assertTrue(self.app._pending_periodic_tasks)
|
|
|
+ assert self.app._pending_periodic_tasks
|
|
|
assert not self.app.configured
|
|
|
|
|
|
sig2 = add.s(4, 4)
|
|
|
- self.assertTrue(self.app.configured)
|
|
|
+ assert self.app.configured
|
|
|
self.app.add_periodic_task(20, sig2, name='add2', expires=4)
|
|
|
- self.assertIn('add1', self.app.conf.beat_schedule)
|
|
|
- self.assertIn('add2', self.app.conf.beat_schedule)
|
|
|
+ assert 'add1' in self.app.conf.beat_schedule
|
|
|
+ assert 'add2' in self.app.conf.beat_schedule
|
|
|
|
|
|
def test_pool_no_multiprocessing(self):
|
|
|
with mock.mask_modules('multiprocessing.util'):
|
|
|
pool = self.app.pool
|
|
|
- self.assertIs(pool, self.app._pool)
|
|
|
+ assert pool is self.app._pool
|
|
|
|
|
|
def test_bugreport(self):
|
|
|
- self.assertTrue(self.app.bugreport())
|
|
|
+ assert self.app.bugreport()
|
|
|
|
|
|
def test_send_task__connection_provided(self):
|
|
|
connection = Mock(name='connection')
|
|
@@ -896,8 +872,8 @@ class test_App(AppCase):
|
|
|
exchange='moo_exchange', routing_key='moo_exchange',
|
|
|
event_dispatcher=dispatcher,
|
|
|
)
|
|
|
- self.assertTrue(dispatcher.sent)
|
|
|
- self.assertEqual(dispatcher.sent[0][0], 'task-sent')
|
|
|
+ assert dispatcher.sent
|
|
|
+ assert dispatcher.sent[0][0] == 'task-sent'
|
|
|
self.app.amqp.send_task_message(
|
|
|
prod, 'footask', message, event_dispatcher=dispatcher,
|
|
|
exchange='bar_exchange', routing_key='bar_exchange',
|
|
@@ -909,56 +885,56 @@ class test_App(AppCase):
|
|
|
self.app.amqp.queues.select.assert_called_with({'foo', 'bar'})
|
|
|
|
|
|
|
|
|
-class test_defaults(AppCase):
|
|
|
+class test_defaults:
|
|
|
|
|
|
def test_strtobool(self):
|
|
|
for s in ('false', 'no', '0'):
|
|
|
- self.assertFalse(defaults.strtobool(s))
|
|
|
+ assert not defaults.strtobool(s)
|
|
|
for s in ('true', 'yes', '1'):
|
|
|
- self.assertTrue(defaults.strtobool(s))
|
|
|
- with self.assertRaises(TypeError):
|
|
|
+ assert defaults.strtobool(s)
|
|
|
+ with pytest.raises(TypeError):
|
|
|
defaults.strtobool('unsure')
|
|
|
|
|
|
|
|
|
-class test_debugging_utils(AppCase):
|
|
|
+class test_debugging_utils:
|
|
|
|
|
|
def test_enable_disable_trace(self):
|
|
|
try:
|
|
|
_app.enable_trace()
|
|
|
- self.assertEqual(_app.app_or_default, _app._app_or_default_trace)
|
|
|
+ assert _app.app_or_default == _app._app_or_default_trace
|
|
|
_app.disable_trace()
|
|
|
- self.assertEqual(_app.app_or_default, _app._app_or_default)
|
|
|
+ assert _app.app_or_default == _app._app_or_default
|
|
|
finally:
|
|
|
_app.disable_trace()
|
|
|
|
|
|
|
|
|
-class test_pyimplementation(AppCase):
|
|
|
+class test_pyimplementation:
|
|
|
|
|
|
def test_platform_python_implementation(self):
|
|
|
with mock.platform_pyimp(lambda: 'Xython'):
|
|
|
- self.assertEqual(pyimplementation(), 'Xython')
|
|
|
+ assert pyimplementation() == 'Xython'
|
|
|
|
|
|
def test_platform_jython(self):
|
|
|
with mock.platform_pyimp():
|
|
|
with mock.sys_platform('java 1.6.51'):
|
|
|
- self.assertIn('Jython', pyimplementation())
|
|
|
+ assert 'Jython' in pyimplementation()
|
|
|
|
|
|
def test_platform_pypy(self):
|
|
|
with mock.platform_pyimp():
|
|
|
with mock.sys_platform('darwin'):
|
|
|
with mock.pypy_version((1, 4, 3)):
|
|
|
- self.assertIn('PyPy', pyimplementation())
|
|
|
+ assert 'PyPy' in pyimplementation()
|
|
|
with mock.pypy_version((1, 4, 3, 'a4')):
|
|
|
- self.assertIn('PyPy', pyimplementation())
|
|
|
+ assert 'PyPy' in pyimplementation()
|
|
|
|
|
|
def test_platform_fallback(self):
|
|
|
with mock.platform_pyimp():
|
|
|
with mock.sys_platform('darwin'):
|
|
|
with mock.pypy_version():
|
|
|
- self.assertEqual('CPython', pyimplementation())
|
|
|
+ assert 'CPython' == pyimplementation()
|
|
|
|
|
|
|
|
|
-class test_shared_task(AppCase):
|
|
|
+class test_shared_task:
|
|
|
|
|
|
def test_registers_to_all_apps(self):
|
|
|
with self.Celery('xproj', set_as_current=True) as xproj:
|
|
@@ -972,16 +948,16 @@ class test_shared_task(AppCase):
|
|
|
def bar():
|
|
|
return 84
|
|
|
|
|
|
- self.assertIs(foo.app, xproj)
|
|
|
- self.assertIs(bar.app, xproj)
|
|
|
- self.assertTrue(foo._get_current_object())
|
|
|
+ assert foo.app is xproj
|
|
|
+ assert bar.app is xproj
|
|
|
+ assert foo._get_current_object()
|
|
|
|
|
|
with self.Celery('yproj', set_as_current=True) as yproj:
|
|
|
- self.assertIs(foo.app, yproj)
|
|
|
- self.assertIs(bar.app, yproj)
|
|
|
+ assert foo.app is yproj
|
|
|
+ assert bar.app is yproj
|
|
|
|
|
|
@shared_task()
|
|
|
def baz():
|
|
|
return 168
|
|
|
|
|
|
- self.assertIs(baz.app, yproj)
|
|
|
+ assert baz.app is yproj
|