diff --git a/src/pytest_celery/api/worker.py b/src/pytest_celery/api/worker.py index e28edd180..51b7717b7 100644 --- a/src/pytest_celery/api/worker.py +++ b/src/pytest_celery/api/worker.py @@ -31,6 +31,9 @@ def worker_name(self) -> str: def worker_queue(self) -> str: return self.container.worker_queue() + def hostname(self) -> str: + return f"{self.worker_name}@{super().hostname()}" + class CeleryWorkerCluster(CeleryTestCluster): def __init__(self, *workers: tuple[CeleryTestWorker | CeleryTestContainer]) -> None: diff --git a/tests/integration/api/test_base.py b/tests/integration/api/test_base.py index 907eb1836..116af4559 100644 --- a/tests/integration/api/test_base.py +++ b/tests/integration/api/test_base.py @@ -24,7 +24,7 @@ def test_name(self, node: CeleryTestNode): def test_hostname(self, node: CeleryTestNode): hostname = node.hostname() assert isinstance(hostname, str) - assert len(hostname) == 12 + assert node.container.id[:12] in hostname @pytest.mark.parametrize("signal", [None, "SIGKILL"]) def test_kill(self, node: CeleryTestNode, signal: str | int): diff --git a/tests/integration/api/test_worker.py b/tests/integration/api/test_worker.py index 45669577f..9f526f770 100644 --- a/tests/integration/api/test_worker.py +++ b/tests/integration/api/test_worker.py @@ -20,6 +20,12 @@ def test_app(self, worker: CeleryTestWorker, celery_setup_app: Celery): def test_version(self, worker: CeleryTestWorker): assert worker.version == CeleryWorkerContainer.version() + def test_hostname(self, worker: CeleryTestWorker): + hostname = worker.hostname() + assert "@" in hostname + assert worker.worker_name in hostname.split("@")[0] + assert worker.container.id[:12] in hostname.split("@")[1] + def test_wait_for_log(self, worker: CeleryTestWorker): log = f"{IntegrationWorkerContainer.worker_name()}@{worker.hostname()} v{worker.version}" worker.wait_for_log(log, "test_celey_test_worker.test_wait_for_log") diff --git a/tests/unit/api/test_base.py b/tests/unit/api/test_base.py index de4ff52fc..cceacc3f7 100644 --- a/tests/unit/api/test_base.py +++ b/tests/unit/api/test_base.py @@ -63,7 +63,7 @@ def test_name(self, node: CeleryTestNode): assert node.name() def test_hostname(self, node: CeleryTestNode): - assert node.hostname() + assert node.container.id[:12] in node.hostname() def test_kill(self, node: CeleryTestNode): node.kill()