From 471018b0cb5dc98cc9020dc5f401d5500b93739a Mon Sep 17 00:00:00 2001 From: Tomer Nosrati Date: Sun, 17 Mar 2024 21:38:09 +0200 Subject: [PATCH] Hotfix: Override test node config using super().config(kwargs) --- examples/vhost/tests/conftest.py | 2 +- src/pytest_celery/api/base.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/vhost/tests/conftest.py b/examples/vhost/tests/conftest.py index 87a5bf9dd..18f354d84 100644 --- a/examples/vhost/tests/conftest.py +++ b/examples/vhost/tests/conftest.py @@ -39,7 +39,7 @@ def celery_broker_cluster(redis_broker: RedisTestBroker) -> CeleryBrokerCluster: class MyRedisTestBackend(RedisTestBackend): def config(self, *args: tuple, **kwargs: dict) -> dict: - return super().config(vhost=1, *args, **kwargs) + return super().config(vhost="1", *args, **kwargs) @pytest.fixture diff --git a/src/pytest_celery/api/base.py b/src/pytest_celery/api/base.py index bfed5e031..725957d91 100644 --- a/src/pytest_celery/api/base.py +++ b/src/pytest_celery/api/base.py @@ -74,7 +74,19 @@ def ready(self) -> bool: def config(self, *args: tuple, **kwargs: dict) -> dict: """Compile the configurations required for Celery from this node.""" - return self.container.celeryconfig + config = self.container.celeryconfig + + if not args and not kwargs: + return config + + for key, value in kwargs.items(): + if key == "vhost": + config["url"] = f"{self.container.prefix()}{self.container.hostname}/{value}" + config["host_url"] = f"{self.container.prefix()}localhost:{self.container.port}/{value}" + + config[key] = value + + return config def logs(self) -> str: """Get the logs of the underlying container."""