This document is for pytest_celery's development version, which can be significantly different from previous releases. Get the stable docs here: 1.0.
Test Setup Matrix¶
- Release:
1.1
- Date:
Sep 30, 2024
The plugin simplifies the setup of test environments by utilizing the pytest fixtures mechanism to configure each component of the test setup independently which allows for a high degree of flexibility in matching specific Celery architectures to each test case.
In this guide we’ll discuss how does the setup matrix work and how to use it.
What is the setup matrix?¶
Added in version 1.0.0.
The setup matrix is a combination of all of the possible Celery architectures that can be used with the available Vendors for each test. It is automatically generated by the plugin to match the installed dependencies when using the default configuration, or it can be manually configured to set each test case separately.
The matrix is configured using the Default Fixtures of each component and is available to the test case using the Test Setup.
Common Setups¶
Added in version 1.0.0.
The following snippets show how to use the setup matrix to configure manual setups, overriding the default configuration using the built-in Vendors.
It may be used in conftest.py or in the test file itself.
RabbitMQ Broker and No Backend¶
Use only RabbitMQ as the broker.
@pytest.fixture
def celery_broker_cluster(celery_rabbitmq_broker: RabbitMQTestBroker) -> CeleryBrokerCluster:
cluster = CeleryBrokerCluster(celery_rabbitmq_broker)
yield cluster
cluster.teardown()
@pytest.fixture
def celery_backend_cluster():
return None
RabbitMQ Broker and Redis Backend¶
Use only RabbitMQ as the broker.
@pytest.fixture
def celery_broker_cluster(celery_rabbitmq_broker: RabbitMQTestBroker) -> CeleryBrokerCluster:
cluster = CeleryBrokerCluster(celery_rabbitmq_broker)
yield cluster
cluster.teardown()
Use Redis as the backend.
@pytest.fixture
def celery_backend_cluster(celery_redis_backend: RedisTestBackend) -> CeleryBackendCluster:
cluster = CeleryBackendCluster(celery_redis_backend)
yield cluster
cluster.teardown()
Redis Broker and No Backend¶
Use only Redis as the broker.
@pytest.fixture
def celery_broker_cluster(celery_redis_broker: RedisTestBroker) -> CeleryBrokerCluster:
cluster = CeleryBrokerCluster(celery_redis_broker)
yield cluster
cluster.teardown()
@pytest.fixture
def celery_backend_cluster():
return None
Redis Broker and Redis Backend¶
Use only Redis as the broker.
@pytest.fixture
def celery_broker_cluster(celery_redis_broker: RedisTestBroker) -> CeleryBrokerCluster:
cluster = CeleryBrokerCluster(celery_redis_broker)
yield cluster
cluster.teardown()
Use Redis as the backend.
@pytest.fixture
def celery_backend_cluster(celery_redis_backend: RedisTestBackend) -> CeleryBackendCluster:
cluster = CeleryBackendCluster(celery_redis_backend)
yield cluster
cluster.teardown()
SQS Broker and No Backend¶
Use only Localstack as the broker.
@pytest.fixture
def celery_broker_cluster(celery_localstack_broker: LocalstackTestBroker) -> CeleryBrokerCluster:
cluster = CeleryBrokerCluster(celery_localstack_broker)
yield cluster
cluster.teardown()
@pytest.fixture
def celery_backend_cluster():
return None
SQS Broker and Redis Backend¶
Use only Localstack as the broker.
@pytest.fixture
def celery_broker_cluster(celery_localstack_broker: LocalstackTestBroker) -> CeleryBrokerCluster:
cluster = CeleryBrokerCluster(celery_localstack_broker)
yield cluster
cluster.teardown()
Use Redis as the backend.
@pytest.fixture
def celery_backend_cluster(celery_redis_backend: RedisTestBackend) -> CeleryBackendCluster:
cluster = CeleryBackendCluster(celery_redis_backend)
yield cluster
cluster.teardown()