Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: sdk tests [LET-4071] (#4258)
cthomas65703a3f2d02
diff --git a/tests/sdk/conftest.py b/tests/sdk/conftest.pyindex b05eb3d78..ca98cc36c 100644--- a/tests/sdk/conftest.py+++ b/tests/sdk/conftest.py@@ -4,38 +4,51 @@ import timefrom typing import Any, Dict, List, Optional, Tupleimport pytest+import requestsfrom dotenv import load_dotenvfrom letta_client import Letta-def run_server():- load_dotenv()[email protected](scope="session")+def server_url() -> str:+ """+ Provides the URL for the Letta server.+ If LETTA_SERVER_URL is not set, starts the server in a background thread+ and polls until it's accepting connections.+ """- from letta.server.rest_api.app import start_server+ def _run_server() -> None:+ load_dotenv()+ from letta.server.rest_api.app import start_server- print("Starting server...")- start_server(debug=True)+ start_server(debug=True)+ url: str = os.getenv("LETTA_SERVER_URL", "http://localhost:8283")-# This fixture starts the server once for the entire test session[email protected](scope="session")-def server():- # Get URL from environment or start server- server_url = os.getenv("LETTA_SERVER_URL", f"http://localhost:8283")if not os.getenv("LETTA_SERVER_URL"):- print("Starting server thread")- thread = threading.Thread(target=run_server, daemon=True)+ thread = threading.Thread(target=_run_server, daemon=True)thread.start()- time.sleep(5)- return server_url+ # Poll until the server is up (or timeout)+ timeout_seconds = 30+ deadline = time.time() + timeout_seconds+ while time.time() < deadline:+ try:+ resp = requests.get(url + "/v1/health")+ if resp.status_code < 500:+ break+ except requests.exceptions.RequestException:+ pass+ time.sleep(0.1)+ else:+ raise RuntimeError(f"Could not reach {url} within {timeout_seconds}s")++ return url# This fixture creates a client for each test module@pytest.fixture(scope="session")-def client(server):- # Use the server URL from the server fixture- server_url = server+def client(server_url):print("Running client tests with server:", server_url)# Overide the base_url if the LETTA_API_URL is set