Repository: celery/celery
File: t/smoke/conftest.py (Python)

Code before:


@pytest.fixture
def default_worker_tasks(default_worker_tasks: set) -> set:
    """Use all of the integration and smoke suites tasks in the smoke tests workers."""
    from t.integration import tasks as integration_tests_tasks
    from t.smoke import tasks as smoke_tests_tasks

    default_worker_tasks.add(integration_tests_tasks)
    default_worker_tasks.add(smoke_tests_tasks)
    return default_worker_tasks


# When using integration tests tasks that requires a Redis instance,
# we use pytest-celery to raise a dedicated Redis container for the smoke tests suite that is configured
# to be used by the integration tests tasks.

redis_image = fetch(repository=REDIS_IMAGE)
redis_test_container: RedisContainer = container(
    image="{redis_image.id}",
    ports=REDIS_PORTS,
    environment=REDIS_ENV,
    network="{default_pytest_celery_network.name}",
    wrapper_class=RedisContainer,
    timeout=REDIS_CONTAINER_TIMEOUT,
)


@pytest.fixture(autouse=True)
def set_redis_test_container(redis_test_container: RedisContainer):
    """Configure the Redis test container to be used by the integration tests tasks."""
    # get_redis_connection(): will use these settings in the tests environment
    os.environ["REDIS_HOST"] = "localhost"
    os.environ["REDIS_PORT"] = str(redis_test_container.port)


@pytest.fixture
def default_worker_env(default_worker_env: dict, redis_test_container: RedisContainer) -> dict:
    """Add the Redis connection details to the worker environment."""
    # get_redis_connection(): will use these settings when executing tasks in the worker
    default_worker_env.update(
        {
            "REDIS_HOST": redis_test_container.hostname,
            "REDIS_PORT": 6379,
            **LOCALSTACK_CREDS,
        }
    )
    return default_worker_env


@pytest.fixture(scope="session", autouse=True)

Review comment (suggestion):
The `default_redis_broker_command` fixture configures Redis to boot with proper configurations.
Without it, the default config will collapse under the heavy use of the CI

Code after:


@pytest.fixture
def default_worker_tasks(default_worker_tasks: set) -> set:
    """Use all of the integration and smoke suites tasks in the smoke tests workers."""
    from t.integration import tasks as integration_tests_tasks
    from t.smoke import tasks as smoke_tests_tasks

    default_worker_tasks.add(integration_tests_tasks)
    default_worker_tasks.add(smoke_tests_tasks)
    return default_worker_tasks


# When using integration tests tasks that requires a Redis instance,
# we use pytest-celery to raise a dedicated Redis container for the smoke tests suite that is configured
# to be used by the integration tests tasks.

redis_image = fetch(repository=REDIS_IMAGE)
redis_test_container: RedisContainer = container(
    image="{redis_image.id}",
    ports=REDIS_PORTS,
    environment=REDIS_ENV,
    network="{default_pytest_celery_network.name}",
    wrapper_class=RedisContainer,
    timeout=REDIS_CONTAINER_TIMEOUT,
    command=fxtr("default_redis_broker_command"),
)


@pytest.fixture(autouse=True)
def set_redis_test_container(redis_test_container: RedisContainer):
    """Configure the Redis test container to be used by the integration tests tasks."""
    # get_redis_connection(): will use these settings in the tests environment
    os.environ["REDIS_HOST"] = "localhost"
    os.environ["REDIS_PORT"] = str(redis_test_container.port)


@pytest.fixture
def default_worker_env(default_worker_env: dict, redis_test_container: RedisContainer) -> dict:
    """Add the Redis connection details to the worker environment."""
    # get_redis_connection(): will use these settings when executing tasks in the worker
    default_worker_env.update(
        {
            "REDIS_HOST": redis_test_container.hostname,
            "REDIS_PORT": 6379,
            **LOCALSTACK_CREDS,
        }
    )
    return default_worker_env