conftest.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from __future__ import absolute_import, unicode_literals
  2. import os
  3. from functools import wraps
  4. import pytest
  5. from celery.contrib.testing.manager import Manager
  6. TEST_BROKER = os.environ.get('TEST_BROKER', 'pyamqp://')
  7. TEST_BACKEND = os.environ.get('TEST_BACKEND', 'redis://')
  8. def flaky(fun):
  9. @wraps(fun)
  10. def _inner(*args, **kwargs):
  11. for i in reversed(range(3)):
  12. try:
  13. return fun(*args, **kwargs)
  14. except Exception:
  15. if not i:
  16. raise
  17. _inner.__wrapped__ = fun
  18. return _inner
  19. def get_redis_connection():
  20. from redis import StrictRedis
  21. return StrictRedis(host=os.environ.get('REDIS_HOST'))
  22. def get_active_redis_channels():
  23. return get_redis_connection().execute_command('PUBSUB CHANNELS')
  24. @pytest.fixture(scope='session')
  25. def celery_config():
  26. return {
  27. 'broker_url': TEST_BROKER,
  28. 'result_backend': TEST_BACKEND
  29. }
  30. @pytest.fixture(scope='session')
  31. def celery_enable_logging():
  32. return True
  33. @pytest.fixture(scope='session')
  34. def celery_worker_pool():
  35. return 'prefork'
  36. @pytest.fixture(scope='session')
  37. def celery_includes():
  38. return {'t.integration.tasks'}
  39. @pytest.fixture
  40. def app(celery_app):
  41. yield celery_app
  42. @pytest.fixture
  43. def manager(app, celery_session_worker):
  44. return Manager(app)
  45. @pytest.fixture(autouse=True)
  46. def ZZZZ_set_app_current(app):
  47. app.set_current()
  48. app.set_default()