conftest.py 1.2 KB

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