conftest.py 1.1 KB

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