Skip to content

Commit

Permalink
celery extra's are not always available
Browse files Browse the repository at this point in the history
  • Loading branch information
woutdenolf committed Feb 24, 2024
1 parent 40ee732 commit 4164b64
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 23 deletions.
26 changes: 18 additions & 8 deletions src/pytest_celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,27 @@
from pytest_celery.fixtures.broker import *
from pytest_celery.fixtures.setup import *
from pytest_celery.fixtures.worker import *
from pytest_celery.vendors.memcached.api import *
from pytest_celery.vendors.memcached.container import *
from pytest_celery.vendors.memcached.fixtures import *
from pytest_celery.vendors import MissingCeleryDependency
from pytest_celery.vendors.rabbitmq.api import *
from pytest_celery.vendors.rabbitmq.container import *
from pytest_celery.vendors.rabbitmq.fixtures import *
from pytest_celery.vendors.redis.backend.api import *
from pytest_celery.vendors.redis.backend.fixtures import *
from pytest_celery.vendors.redis.broker.api import *
from pytest_celery.vendors.redis.broker.fixtures import *
from pytest_celery.vendors.redis.container import *

try:
from pytest_celery.vendors.memcached.api import *
from pytest_celery.vendors.memcached.container import *
from pytest_celery.vendors.memcached.fixtures import *
except MissingCeleryDependency:
pass

try:
from pytest_celery.vendors.redis.backend.api import *
from pytest_celery.vendors.redis.backend.fixtures import *
from pytest_celery.vendors.redis.broker.api import *
from pytest_celery.vendors.redis.broker.fixtures import *
from pytest_celery.vendors.redis.container import *
except MissingCeleryDependency:
pass

from pytest_celery.vendors.worker.container import *
from pytest_celery.vendors.worker.fixtures import *

Expand Down
41 changes: 26 additions & 15 deletions src/pytest_celery/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,35 @@

from pytest_docker_tools import network

from pytest_celery.vendors.memcached.defaults import CELERY_MEMCACHED_BACKEND
from pytest_celery.vendors.memcached.defaults import *
from pytest_celery.vendors import MissingCeleryDependency
from pytest_celery.vendors.rabbitmq.defaults import CELERY_RABBITMQ_BROKER
from pytest_celery.vendors.rabbitmq.defaults import *
from pytest_celery.vendors.redis.backend.defaults import CELERY_REDIS_BACKEND
from pytest_celery.vendors.redis.backend.defaults import *
from pytest_celery.vendors.redis.broker.defaults import CELERY_REDIS_BROKER
from pytest_celery.vendors.redis.broker.defaults import *
from pytest_celery.vendors.redis.defaults import *
from pytest_celery.vendors.worker.defaults import CELERY_SETUP_WORKER
from pytest_celery.vendors.worker.defaults import *

try:
import pytest_celery.vendors.memcached
except MissingCeleryDependency:
_CELERY_MEMCACHED_BACKEND = None
else:
from pytest_celery.vendors.memcached.defaults import CELERY_MEMCACHED_BACKEND as _CELERY_MEMCACHED_BACKEND
from pytest_celery.vendors.memcached.defaults import *

_CELERY_MEMCACHED_BACKEND = None # Beta support at the moment, to be used manually

try:
import pytest_celery.vendors.redis
except MissingCeleryDependency:
_CELERY_REDIS_BACKEND = None
_CELERY_REDIS_BROKER = None
else:
from pytest_celery.vendors.redis.backend.defaults import CELERY_REDIS_BACKEND as _CELERY_REDIS_BACKEND
from pytest_celery.vendors.redis.backend.defaults import *
from pytest_celery.vendors.redis.broker.defaults import CELERY_REDIS_BROKER as _CELERY_REDIS_BROKER
from pytest_celery.vendors.redis.broker.defaults import *
from pytest_celery.vendors.redis.defaults import *


####################################################################################
# Automatic components
####################################################################################
Expand All @@ -29,14 +46,8 @@
# Tests that do not rely on default parametrization will not be affected.

ALL_CELERY_WORKERS = (CELERY_SETUP_WORKER,)
ALL_CELERY_BACKENDS = (
CELERY_REDIS_BACKEND,
# CELERY_MEMCACHED_BACKEND, # Beta support at the moment, to be used manually
)
ALL_CELERY_BROKERS = (
CELERY_REDIS_BROKER,
CELERY_RABBITMQ_BROKER,
)
ALL_CELERY_BACKENDS = (backend for backend in [_CELERY_REDIS_BACKEND, _CELERY_MEMCACHED_BACKEND] if backend is not None)
ALL_CELERY_BROKERS = (broker for broker in [CELERY_RABBITMQ_BROKER, _CELERY_REDIS_BROKER] if broker is not None)

####################################################################################
# Fixtures
Expand Down
4 changes: 4 additions & 0 deletions src/pytest_celery/vendors/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
"""See :ref:`vendors`."""


class MissingCeleryDependency(ImportError):
pass
7 changes: 7 additions & 0 deletions src/pytest_celery/vendors/memcached/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
This module is part of the Memcached Backend vendor.
"""

from .. import MissingCeleryDependency

try:
import memcache # noqa F401
except ImportError:
raise MissingCeleryDependency("celery extra dependency missing: celery[pymemcache]")
7 changes: 7 additions & 0 deletions src/pytest_celery/vendors/redis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
This module is part of the Redis vendor.
"""

from .. import MissingCeleryDependency

try:
import redis # noqa F401
except ImportError:
raise MissingCeleryDependency("celery extra dependency missing: celery[redis]")

0 comments on commit 4164b64

Please sign in to comment.