conftest.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from __future__ import absolute_import, unicode_literals
  2. import os
  3. import pytest
  4. from functools import wraps
  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. @pytest.fixture(scope='session')
  20. def celery_config():
  21. return {
  22. 'broker_url': TEST_BROKER,
  23. 'result_backend': TEST_BACKEND
  24. }
  25. @pytest.fixture(scope='session')
  26. def celery_enable_logging():
  27. return True
  28. @pytest.fixture(scope='session')
  29. def celery_worker_pool():
  30. return 'prefork'
  31. @pytest.fixture(scope='session')
  32. def celery_includes():
  33. return {'t.integration.tasks'}
  34. @pytest.fixture
  35. def app(celery_app):
  36. yield celery_app
  37. @pytest.fixture
  38. def manager(app, celery_session_worker):
  39. return Manager(app)
  40. @pytest.fixture(autouse=True)
  41. def ZZZZ_set_app_current(app):
  42. app.set_current()
  43. app.set_default()