conftest.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import absolute_import, unicode_literals
  2. import pytest
  3. from cyanide.suite import ManagerMixin
  4. def _celerymark(app, redis_results=None, **kwargs):
  5. if redis_results and not app.conf.result_backend.startswith('redis'):
  6. pytest.skip('Test needs Redis result backend.')
  7. @pytest.fixture
  8. def app(request):
  9. from .app import app
  10. app.finalize()
  11. app.set_current()
  12. mark = request.node.get_marker('celery')
  13. mark = mark and mark.kwargs or {}
  14. _celerymark(app, **mark)
  15. yield app
  16. @pytest.fixture
  17. def manager(app):
  18. with CeleryManager(app) as manager:
  19. yield manager
  20. class CeleryManager(ManagerMixin):
  21. # we don't stop full suite when a task result is missing.
  22. TaskPredicate = AssertionError
  23. def __init__(self, app, no_join=False, **kwargs):
  24. self.app = app
  25. self.no_join = no_join
  26. self._init_manager(app, **kwargs)
  27. def __enter__(self):
  28. return self
  29. def __exit__(self, *exc_info):
  30. self.close()
  31. def close(self):
  32. pass