### Example Requirements Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/hybrid_setup.rst Lists the Python packages required for the hybrid setup example, noting that gevent can be installed independently. ```text pytest>=6.0.0 pytest-celery>=1.0.0 celery[redis,gevent]>=5.0.0 redis gevent ``` -------------------------------- ### Project File Structure Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/hybrid_setup.rst Lists the relevant files and directories for the hybrid setup example. ```text hybrid_setup/ ├── requirements.txt └── tests/ ├── conftest.py ├── test_hybrid_setup.py └── vendors/ ├── __init__.py ├── memcached.py ├── rabbitmq.py └── workers/ ├── __init__.py ├── gevent.Dockerfile ├── gevent.py ├── legacy.Dockerfile ├── legacy.py ├── signals.py └── tasks.py ``` -------------------------------- ### Enable Localstack Broker in Setup Matrix Source: https://github.com/celery/pytest-celery/blob/main/docs/getting-started/vendors.rst Add this configuration to conftest.py to enable the Localstack broker in the default setup matrix if the vendor is installed. ```python from pytest_celery import ALL_CELERY_BROKERS from pytest_celery import CELERY_LOCALSTACK_BROKER from pytest_celery import CeleryTestBroker from pytest_celery import _is_vendor_installed if _is_vendor_installed("localstack"): ALL_CELERY_BROKERS.add(CELERY_LOCALSTACK_BROKER) @pytest.fixture(params=ALL_CELERY_BROKERS) def celery_broker(request: pytest.FixtureRequest) -> CeleryTestBroker: # type: ignore broker: CeleryTestBroker = request.getfixturevalue(request.param) yield broker broker.teardown() ``` -------------------------------- ### CI Workflow: Examples Source: https://github.com/celery/pytest-celery/blob/main/docs/devguide/release.rst Configuration for the CI pipeline that tests the official plugin examples. ```yaml name: Examples on: push: branches: [ main ] pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 - name: Set up Python "${{ matrix.python-version }}" uses: actions/setup-python@v3 with: python-version: "${{ matrix.python-version }}" - name: Install dependencies run: | python -m pip install --upgrade pip pip install tox - name: Test examples with tox run: tox -e examples ``` -------------------------------- ### Install Python Dependencies and Start Celery Worker Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/django.rst Installs project requirements and starts the Celery worker using configured environment variables. Switches to a non-root user for security. ```docker # Install packages WORKDIR /src COPY --chown=test_user:test_user requirements.txt . RUN pip install --no-cache-dir --upgrade pip RUN pip install -r ./requirements.txt # Switch to the test_user USER test_user # Start the celery worker CMD celery -A proj worker --loglevel=$LOG_LEVEL -n $WORKER_NAME@%h -Q $WORKER_QUEUE ``` -------------------------------- ### Install pytest-celery with all stable vendors Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/advanced-installation.rst This command installs the plugin and configures it to use all available stable vendors. It installs dependencies for all stable vendors, enabling manual configuration of the setup matrix for each test case. ```bash pip install "pytest-celery[all]" ``` -------------------------------- ### Dockerfile Package Installation Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/myworker.rst Sets the working directory, copies requirements, and installs Celery from source. ```docker # Install packages WORKDIR /src COPY --chown=test_user:test_user requirements.txt . RUN pip install --no-cache-dir --upgrade pip RUN pip install -r ./requirements.txt RUN git clone https://github.com/celery/celery.git WORKDIR /src/celery RUN pip install -e . ``` -------------------------------- ### Worker Pool Example File Structure Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/worker_pool.rst Lists the relevant files for the worker pool example project. ```text rabbitmq_management/ ├── tests/ │ ├── __init__.py │ └── test_gevent_pool.py │ └── test_solo_pool.py └── Dockerfile └── tasks.py └── requirements.txt ``` -------------------------------- ### Project File Structure Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/rabbitmq_management.rst Lists the relevant files in the example project for setting up RabbitMQ management. ```text rabbitmq_management/ ├── tests/ │ ├── __init__.py │ ├── conftest.py │ └── test_management_broker.py └── requirements.txt ``` -------------------------------- ### Project File Structure Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/vhost.rst Lists the relevant files in the example project for vhost configuration. ```text rabbitmq_management/ ├── tests/ │ ├── __init__.py │ ├── conftest.py │ └── test_vhost.py └── requirements.txt ``` -------------------------------- ### Install pytest-celery with Redis vendor Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/advanced-installation.rst Use this command to install the plugin with the Redis vendor. This installs the plugin, Celery, Kombu, and the Redis package, configuring the plugin to use Redis as the broker and backend. ```bash pip install "pytest-celery[redis]" ``` -------------------------------- ### Install Development Dependencies with Poetry Source: https://github.com/celery/pytest-celery/blob/main/docs/devguide/local-development-environment.rst Install all development dependencies, including test, dev, ci, and docs extras, using Poetry. ```bash poetry install -E "all" --with test,dev,ci,docs ``` -------------------------------- ### File Structure Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/myutils.rst Lists the relevant files in the project for the myutils example. ```text myutils/ ├── tests/ │ ├── __init__.py │ ├── conftest.py │ ├── myutils.py │ └── test_myutils.py └── requirements.txt ``` -------------------------------- ### Testing a Custom Task Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/celery-bug-report.rst Example test case that uses a custom task. This demonstrates how to apply and get the result of a task. ```python from tasks import mytask def test_issue_1234(celery_setup: CeleryTestSetup): # Running this canvas causes an unexpected exception as described in the bug report... assert mytask.s().apply_async().get() is None, "The bug causes this assertion to fail..." ``` -------------------------------- ### Get Setup Size with `celery_setup` Source: https://context7.com/celery/pytest-celery/llms.txt Determine the total number of nodes (workers, brokers, backends) in the test environment by checking the length of the `celery_setup` object. ```python from pytest_celery import CeleryTestSetup def test_setup_size(celery_setup: CeleryTestSetup): # Total number of nodes (workers + brokers + backends) print(len(celery_setup)) # e.g. 3 ``` -------------------------------- ### Test Case Example Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/hybrid_setup.rst Illustrates a test case that utilizes the celery_setup fixture to run scenarios within the configured hybrid Celery environment. ```python TestHybridSetupExample: def test_example(self, celery_setup): assert celery_setup.tasks.identity.s("Hello,").get() == "Hello," assert celery_setup.tasks.identity.s("world!").get() == "world!" def test_failover(self, celery_setup, redis_primary, redis_failover): # Test failover by stopping the primary broker redis_primary.stop() assert celery_setup.tasks.identity.s("Hello,").get() == "Hello," assert celery_setup.tasks.identity.s("world!").get() == "world!" def test_legacy_queue(self, celery_setup): assert celery_setup.tasks.identity.s("Hello,").get() == "Hello," assert celery_setup.tasks.identity.s("world!").get() == "world!" def test_gevent_pool(self, celery_setup): assert celery_setup.tasks.identity.s("Hello,").get() == "Hello," assert celery_setup.tasks.identity.s("world!").get() == "world!" def test_prefork_pool(self, celery_setup): assert celery_setup.tasks.identity.s("Hello,").get() == "Hello," assert celery_setup.tasks.identity.s("world!").get() == "world!" ``` -------------------------------- ### Django Project File Structure Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/django.rst Overview of the file structure for the Django example project. ```text django/ ├── demoapp/ │ ├── tasks.py ├── tests/ │ ├── __init__.py │ ├── conftest.py │ └── DjangoWorker.Dockerfile │ └── test_tasks.py └── requirements.txt ``` -------------------------------- ### Test Broker Configuration in Setup Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/rabbitmq_management.rst Verifies that the broker within a full test setup is an instance of RabbitMQManagementTestBroker and checks the queues API. ```python def test_broker_in_setup(celery_setup: CeleryTestSetup): assert isinstance(celery_setup.broker, RabbitMQManagementTestBroker) api = celery_setup.broker.get_management_url() + "/api/queues" response = requests.get(api, auth=HTTPBasicAuth("guest", "guest")) assert response.status_code == 200 res = response.json() assert isinstance(res, list) assert len(list(filter(lambda queues: celery_setup.worker.hostname() in queues["name"], res))) == 1 ``` -------------------------------- ### Redis Broker and Redis Backend Setup Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/setup-matrix.rst Configure Redis as both the broker and the backend. This setup is ideal for tests that use Redis for both message queuing and result storage. ```python @pytest.fixture def celery_broker_cluster(celery_redis_broker: RedisTestBroker) -> CeleryBrokerCluster: cluster = CeleryBrokerCluster(celery_redis_broker) yield cluster cluster.teardown() ``` ```python @pytest.fixture def celery_backend_cluster(celery_redis_backend: RedisTestBackend) -> CeleryBackendCluster: cluster = CeleryBackendCluster(celery_redis_backend) yield cluster cluster.teardown() ``` -------------------------------- ### Install pytest-celery with All Vendors Source: https://github.com/celery/pytest-celery/blob/main/docs/includes/installation.txt Installs pytest-celery with support for all available built-in vendors. ```console pip install -U "pytest-celery[all]" ``` -------------------------------- ### RabbitMQ Broker and Redis Backend Setup Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/setup-matrix.rst Configure RabbitMQ as the broker and Redis as the backend. This setup is suitable for tests requiring message queuing with Redis for result storage. ```python @pytest.fixture def celery_broker_cluster(celery_rabbitmq_broker: RabbitMQTestBroker) -> CeleryBrokerCluster: cluster = CeleryBrokerCluster(celery_rabbitmq_broker) yield cluster cluster.teardown() ``` ```python @pytest.fixture def celery_backend_cluster(celery_redis_backend: RedisTestBackend) -> CeleryBackendCluster: cluster = CeleryBackendCluster(celery_redis_backend) yield cluster cluster.teardown() ``` -------------------------------- ### Create Worker User and Install Dependencies Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/django.rst Creates a dedicated user for running the worker and installs essential system dependencies. ```docker # Create a user to run the worker RUN adduser --disabled-password --gecos "" test_user # Install system dependencies RUN apt-get update && apt-get install -y build-essential git ``` -------------------------------- ### Redis Broker and No Backend Setup Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/setup-matrix.rst Configure Redis as the broker and disable the backend. This setup is for tests that use Redis for message queuing but do not need result storage. ```python @pytest.fixture def celery_broker_cluster(celery_redis_broker: RedisTestBroker) -> CeleryBrokerCluster: cluster = CeleryBrokerCluster(celery_redis_broker) yield cluster cluster.teardown() ``` ```python @pytest.fixture def celery_backend_cluster(): return None ``` -------------------------------- ### Install pytest-celery Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/celery-bug-report.rst Install the pytest-celery plugin with all extras for comprehensive testing. Then, run pytest with specific flags to execute tests, such as 'test_issue_1234.py'. ```console pip install -U "pytest-celery[all]" pytest -xsv test_issue_1234.py ``` -------------------------------- ### RabbitMQ Broker and No Backend Setup Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/setup-matrix.rst Configure RabbitMQ as the broker and disable the backend. This setup is useful for tests that only require message queuing without result storage. ```python @pytest.fixture def celery_broker_cluster(celery_rabbitmq_broker: RabbitMQTestBroker) -> CeleryBrokerCluster: cluster = CeleryBrokerCluster(celery_rabbitmq_broker) yield cluster cluster.teardown() ``` ```python @pytest.fixture def celery_backend_cluster(): return None ``` -------------------------------- ### SQS Broker and Redis Backend Setup Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/setup-matrix.rst Configure Localstack as the SQS broker and Redis as the backend. This setup is for tests using SQS for message queuing and Redis for result storage. ```python @pytest.fixture def celery_broker_cluster(celery_localstack_broker: LocalstackTestBroker) -> CeleryBrokerCluster: cluster = CeleryBrokerCluster(celery_localstack_broker) yield cluster cluster.teardown() ``` ```python @pytest.fixture def celery_backend_cluster(celery_redis_backend: RedisTestBackend) -> CeleryBackendCluster: cluster = CeleryBackendCluster(celery_redis_backend) yield cluster cluster.teardown() ``` -------------------------------- ### Check Celery Test Setup Readiness Source: https://context7.com/celery/pytest-celery/llms.txt Validates that all components in the setup are operational. Accepts optional flags to enable deeper checks via task ping or Celery control ping, at the cost of additional overhead. ```python from pytest_celery import CeleryTestSetup def test_ready_options(celery_setup: CeleryTestSetup): # Default: Docker containers only (fastest) assert celery_setup.ready(docker=True, ping=False, control=False) # With task-level ping (dispatches a ping task to each worker) assert celery_setup.ready(ping=True) # With control-level ping (uses celery.control.ping()) assert celery_setup.ready(control=True) # Full check assert celery_setup.ready(ping=True, control=True, docker=True) ``` -------------------------------- ### Docker Command: Pull RabbitMQ & Redis Source: https://github.com/celery/pytest-celery/blob/main/docs/devguide/release.rst Start RabbitMQ and Redis containers for integration tests. ```console docker run -d -p 6379:6379 --name redis redis:latest docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq rabbitmq:management ``` -------------------------------- ### Cleanup and Reinstall Dependencies Source: https://github.com/celery/pytest-celery/blob/main/docs/devguide/local-development-environment.rst Use this snippet for easy cleanup and reinstallation of dependencies during development. It uninstalls existing packages and then installs them using Poetry. ```bash pip uninstall pytest-celery celery -y && pip freeze | cut -d "@" -f1 | xargs pip uninstall -y; pip install -U pip ipython; poetry install -E "all" --with test,dev,ci,docs ``` -------------------------------- ### Install pytest-celery with Vendor Extras Source: https://github.com/celery/pytest-celery/blob/main/docs/includes/installation.txt Installs pytest-celery with specific vendor dependencies. Replace with the desired vendor name (e.g., redis, memcached, sqs, all). ```console pip install -U "pytest-celery[]" ``` -------------------------------- ### Celery Task Workflow Example Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/hybrid_setup.rst Defines a Celery task chain using groups and sequential tasks, routing a specific task to a 'legacy' queue. ```python canvas = ( group( identity.si("Hello, "), identity.si("world!"), ) | noop.s().set(queue="legacy") | identity.si("Done!") ) ``` -------------------------------- ### Standalone Bug Report Script Example Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/celery-bug-report.rst A complete Python script that can be used as a starting point for a Celery bug report. It includes setup for RabbitMQ, Redis, and a built-in worker. ```python import pytest from pytest_celery import CeleryTestSetup @pytest.fixture(scope="session") def default_worker_celery_version() -> str: # Use a specific Celery release for the built-in worker return "4.4.7" @pytest.fixture(scope="session") def default_worker_tasks(default_worker_tasks: set) -> set: # Inject custom tasks into the worker from . import tasks default_worker_tasks.add(tasks) return default_worker_tasks class TestBug: def test_issue_1234(self, celery_setup: CeleryTestSetup): # Running this canvas causes an unexpected exception as described in the bug report... from .tasks import mytask assert mytask.s().apply_async().get() is None, "The bug causes this assertion to fail..." # To reproduce the bug report: # 1. Create a new file, e.g. test_issue_1234.py # 2. Copy and paste the snippet into the new file. # 3. Run pytest. ``` -------------------------------- ### Write a Basic 'Hello, World!' Test Case Source: https://github.com/celery/pytest-celery/blob/main/docs/getting-started/first-steps.rst A simple test case that verifies the configured broker and backend types and executes the 'noop' task, asserting its return value. ```python def test_hello_world(celery_setup: CeleryTestSetup): assert isinstance(celery_setup.broker, RabbitMQTestBroker) assert isinstance(celery_setup.backend, RedisTestBackend) assert noop.s().apply_async().get() is None ``` -------------------------------- ### Full Readiness Check with `celery_setup` Source: https://context7.com/celery/pytest-celery/llms.txt Perform a comprehensive readiness check including Docker, control ping, and task ping using the `celery_setup` fixture. This ensures the Celery environment is fully operational. ```python from pytest_celery import CeleryTestSetup def test_full_readiness(celery_setup: CeleryTestSetup): # Full readiness: Docker + control ping + task ping assert celery_setup.ready(ping=True, control=True, docker=True) ``` -------------------------------- ### Get Celery Versions in Range Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/range.rst Fetches a sorted list of Celery versions from PyPI within a specified start and end version. It filters out pre-release versions. ```python import requests from packaging.version import parse as parse_version def get_celery_versions(start_version: str, end_version: str) -> list[str]: url = "https://pypi.org/pypi/celery/json" response = requests.get(url) data = response.json() all_versions = data["releases"].keys() filtered_versions = [ v for v in all_versions if ( parse_version(start_version) <= parse_version(v) <= parse_version(end_version) and not parse_version(v).is_prerelease ) ] return sorted(filtered_versions, key=parse_version) ``` -------------------------------- ### CeleryTestSetup.ready() Source: https://context7.com/celery/pytest-celery/llms.txt Validates that all components in the setup are operational. Accepts optional flags to enable deeper checks via task ping or Celery control ping, at the cost of additional overhead. ```APIDOC ## CeleryTestSetup.ready() ### Description Validates that all components in the setup are operational. Accepts optional flags to enable deeper checks via task ping or Celery control ping, at the cost of additional overhead. ### Parameters #### Query Parameters - **docker** (bool) - Optional - Enable Docker container checks. - **ping** (bool) - Optional - Enable task-level ping. - **control** (bool) - Optional - Enable Celery control ping. ### Request Example ```python assert celery_setup.ready(docker=True, ping=False, control=False) assert celery_setup.ready(ping=True) assert celery_setup.ready(control=True) assert celery_setup.ready(ping=True, control=True, docker=True) ``` ``` -------------------------------- ### Install pytest-celery Source: https://github.com/celery/pytest-celery/blob/main/docs/includes/installation.txt Installs the latest version of pytest-celery and its core dependencies. ```console pip install -U pytest-celery ``` -------------------------------- ### Basic Readiness Check with `celery_setup` Source: https://context7.com/celery/pytest-celery/llms.txt The `celery_setup` fixture provides a basic readiness check for Docker containers. This test function will run against all configured broker/backend combinations. ```python from pytest_celery import CeleryTestSetup def test_hello_world(celery_setup: CeleryTestSetup): # Shallow readiness check (Docker containers are up) assert celery_setup.ready() ``` -------------------------------- ### Basic Test Setup with pytest-celery Source: https://github.com/celery/pytest-celery/blob/main/docs/getting-started/introduction.rst Demonstrates a basic test case using the `celery_setup` fixture to assert readiness. This code generates test cases for all possible combinations of supported brokers and backends. ```python def test_hello_world(celery_setup: CeleryTestSetup): assert celery_setup.ready() ``` -------------------------------- ### Test Custom Function via Full Setup Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/myutils.rst Tests the 'myfunc' function using a full Celery setup ('celery_setup'). This involves accessing the worker through the setup fixture and calling the custom function via its API. ```python def test_myfunc_in_setup_worker(celery_setup: CeleryTestSetup): celery_worker: MyWorker = celery_setup.worker assert celery_worker.myfunc() == "foo" assert celery_worker.get_running_processes_info() ``` -------------------------------- ### Celery Tasks for Gevent Example Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/worker_pool.rst Defines Celery tasks, adapted from the Celery gevent example. ```python from celery import Celery app = Celery('tasks', broker='redis://localhost:6379/0') @app.task def add(x, y): return x + y ``` -------------------------------- ### Install pytest-celery with RabbitMQ & Redis Source: https://github.com/celery/pytest-celery/blob/main/docs/includes/installation.txt Installs pytest-celery with RabbitMQ (default) and Redis vendor support for testing. ```console pip install -U "pytest-celery[redis]" ``` -------------------------------- ### Execute docs-livehtml Environment Source: https://github.com/celery/pytest-celery/blob/main/docs/devguide/tox.rst Command to run the 'docs-livehtml' tox environment for serving documentation locally with live reloading. ```bash tox -e docs-livehtml ``` -------------------------------- ### Interact with CeleryTestSetup in a Test Source: https://context7.com/celery/pytest-celery/llms.txt Use the `celery_setup` fixture to access the Celery app, dispatch tasks, and inspect worker details. The `ready()` method confirms Docker containers are operational. ```python from pytest_celery import CeleryTestSetup, RabbitMQTestBroker, RedisTestBackend from myapp.tasks import add def test_add_task(celery_setup: CeleryTestSetup): # setup.ready() confirms all Docker containers are up assert celery_setup.ready() assert isinstance(celery_setup.broker, RabbitMQTestBroker) assert isinstance(celery_setup.backend, RedisTestBackend) # Access the configured Celery app directly app = celery_setup.app assert app is not None # Dispatch a task and collect the result result = add.s(4, 6).apply_async() assert result.get(timeout=30) == 10 # Access the first worker node worker = celery_setup.worker print(worker.version) # e.g. "5.3.6" print(worker.worker_queue) # e.g. "celery" print(worker.logs()) # full container stdout ``` -------------------------------- ### Install pytest-celery with SQS & Redis Source: https://github.com/celery/pytest-celery/blob/main/docs/includes/installation.txt Installs pytest-celery with SQS (via Localstack) and Redis vendor support for testing. ```console pip install -U "pytest-celery[redis,sqs]" ``` -------------------------------- ### CeleryTestSetup Fixture Source: https://context7.com/celery/pytest-celery/llms.txt The `celery_setup` fixture provides the main entry point for interacting with the Celery test environment. It is automatically parametrized to run tests against all combinations of configured brokers, backends, and workers. ```APIDOC ## `celery_setup` fixture — Parameterized environment fixture The `celery_setup` fixture is the primary pytest fixture that assembles all configured clusters into a ready-to-use `CeleryTestSetup`. It is automatically parametrized for every combination of enabled workers, brokers, and backends, so a single test function runs against the full matrix. ### Usage Example ```python # A single test runs against ALL broker/backend combinations automatically: # e.g. [celery_setup_worker-celery_rabbitmq_broker-celery_redis_backend] # [celery_setup_worker-celery_redis_broker-celery_redis_backend] from pytest_celery import CeleryTestSetup def test_hello_world(celery_setup: CeleryTestSetup): # Shallow readiness check (Docker containers are up) assert celery_setup.ready() def test_full_readiness(celery_setup: CeleryTestSetup): # Full readiness: Docker + control ping + task ping assert celery_setup.ready(ping=True, control=True, docker=True) def test_setup_size(celery_setup: CeleryTestSetup): # Total number of nodes (workers + brokers + backends) print(len(celery_setup)) # e.g. 3 ``` ### Parameters - **celery_setup** (`CeleryTestSetup`): The main test environment object, injected into tests. ### Methods - **`ready(ping=False, control=False, docker=True)`**: Checks the readiness of the test environment. - `ping` (bool): If True, performs a Celery ping. - `control` (bool): If True, performs a control command ping. - `docker` (bool): If True, checks if Docker containers are running. - **`len(celery_setup)`**: Returns the total number of nodes (workers, brokers, backends) in the setup. ``` -------------------------------- ### Install Dependencies for Pytest Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/celery-bug-report.rst Commands to install the Celery project in editable mode and its test dependencies before running tests with Pytest. ```console pip install -e . pip install -r requirements/test.txt ``` -------------------------------- ### List All Tox Environments Source: https://github.com/celery/pytest-celery/blob/main/docs/devguide/tox.rst Run this command to see all available tox environments. ```bash tox -av ``` -------------------------------- ### vhost Test Example Source: https://github.com/celery/pytest-celery/blob/main/docs/userguide/examples/vhost.rst Includes the test file that demonstrates running Celery tests using the same Redis container for both broker and backend components with different vhosts. ```python from __future__ import annotations import pytest from celery_testing.brokers import CeleryBrokerCluster, RedisTestBroker from celery_testing.backends import CeleryBackendCluster, RedisTestBackend class MyRedisTestBackend(RedisTestBackend): def config(self, *args: tuple, **kwargs: dict) -> dict: return super().config(vhost=1, *args, **kwargs) @pytest.Marked.parametrize( "celery_broker_cluster, celery_backend_cluster", [( CeleryBrokerCluster(RedisTestBroker(redis_test_container)), CeleryBackendCluster(MyRedisTestBackend(redis_test_container)), )], indirect=True, ) def test_vhost( celery_broker_cluster: CeleryBrokerCluster, celery_backend_cluster: CeleryBackendCluster, ) -> None: """Test that vhost configuration works correctly.""" celery_broker_cluster.broker.send_task("tasks.add", args=(2, 2)) result = celery_backend_cluster.backend.get_task_result(celery_broker_cluster.broker.tasks[0].id) assert result.get() == 4 ```