conftest.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. @pytest.fixture(scope='session')
  23. def celery_config():
  24. return {
  25. 'broker_url': TEST_BROKER,
  26. 'result_backend': TEST_BACKEND
  27. }
  28. @pytest.fixture(scope='session')
  29. def celery_enable_logging():
  30. return True
  31. @pytest.fixture(scope='session')
  32. def celery_worker_pool():
  33. return 'prefork'
  34. @pytest.fixture(scope='session')
  35. def celery_includes():
  36. return {'t.integration.tasks'}
  37. @pytest.fixture
  38. def app(celery_app):
  39. yield celery_app
  40. @pytest.fixture
  41. def manager(app, celery_session_worker):
  42. return Manager(app)
  43. @pytest.fixture(autouse=True)
  44. def ZZZZ_set_app_current(app):
  45. app.set_current()
  46. app.set_default()