From e7c276d4902cafaa4804023e1d671a9e00bda379 Mon Sep 17 00:00:00 2001 From: Callum Forrester Date: Mon, 16 Dec 2024 17:13:37 +0000 Subject: [PATCH] :Wait for server to start in system tests --- tests/system_tests/test_blueapi_system.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/system_tests/test_blueapi_system.py b/tests/system_tests/test_blueapi_system.py index 477a637c3..5aa08ff0b 100644 --- a/tests/system_tests/test_blueapi_system.py +++ b/tests/system_tests/test_blueapi_system.py @@ -5,6 +5,7 @@ import pytest from bluesky_stomp.models import BasicAuthentication from pydantic import TypeAdapter +from requests.exceptions import ConnectionError from blueapi.client.client import ( BlueapiClient, @@ -43,7 +44,7 @@ @pytest.fixture -def client_without_auth(tmp_path) -> BlueapiClient: +def client_without_auth(tmp_path: Path) -> BlueapiClient: return BlueapiClient.from_config(config=ApplicationConfig(auth_token_path=tmp_path)) @@ -58,6 +59,22 @@ def client_with_stomp() -> BlueapiClient: ) +@pytest.fixture(scope="module", autouse=True) +def wait_for_server(): + client = BlueapiClient.from_config(config=ApplicationConfig()) + + attempts_remaining = 20 + while attempts_remaining > 0: + try: + client.get_environment() + return + except ConnectionError: + ... + attempts_remaining -= 1 + time.sleep(0.5) + raise TimeoutError("No connection to the blueapi server") + + # This client will have auth enabled if it finds cached valid token @pytest.fixture def client() -> BlueapiClient: