From fd4c0bca8e71d3bea1ab4e3ad3c62f57c6c05a54 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 26 Oct 2025 16:39:31 +0100 Subject: [PATCH 1/3] Type hints in conftest.py --- tests/integration/conftest.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 066e110af..50a7d5622 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -2,6 +2,7 @@ from pathlib import Path +from typing import Generator import pytest from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker @@ -11,7 +12,7 @@ @pytest.fixture(autouse=True) -def reset_configuration_state(): +def reset_configuration_state() -> Generator: """Reset configuration state before each integration test. This autouse fixture ensures test independence by resetting the @@ -25,7 +26,7 @@ def reset_configuration_state(): @pytest.fixture(name="test_config", scope="function") -def test_config_fixture(): +def test_config_fixture() -> Generator: """Load real configuration for integration tests. This fixture loads the actual configuration file used in testing, @@ -44,7 +45,7 @@ def test_config_fixture(): @pytest.fixture(name="test_db_engine", scope="function") -def test_db_engine_fixture(): +def test_db_engine_fixture() -> Generator: """Create an in-memory SQLite database engine for testing. This provides a real database (not mocked) for integration tests. @@ -68,7 +69,7 @@ def test_db_engine_fixture(): @pytest.fixture(name="test_db_session", scope="function") -def test_db_session_fixture(test_db_engine): +def test_db_session_fixture(test_db_engine) -> Generator: """Create a database session for testing. Provides a real database session connected to the in-memory test database. From 4b13e367dc35a4e3b92ebd479352643e776845a7 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 26 Oct 2025 16:39:42 +0100 Subject: [PATCH 2/3] Type hints in test_info_integration.py --- .../endpoints/test_info_integration.py | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/integration/endpoints/test_info_integration.py b/tests/integration/endpoints/test_info_integration.py index 32222dfbd..818676b3b 100644 --- a/tests/integration/endpoints/test_info_integration.py +++ b/tests/integration/endpoints/test_info_integration.py @@ -1,6 +1,9 @@ """Integration tests for the /info endpoint.""" import pytest +from typing import Generator +from pytest_mock import MockerFixture + from fastapi import HTTPException, Request, status from llama_stack_client import APIConnectionError from llama_stack_client.types import VersionInfo @@ -11,7 +14,7 @@ @pytest.fixture(name="mock_llama_stack_client") -def mock_llama_stack_client_fixture(mocker): +def mock_llama_stack_client_fixture(mocker: MockerFixture) -> Generator: """Mock only the external Llama Stack client. This is the only external dependency we mock for integration tests, @@ -31,7 +34,7 @@ def mock_llama_stack_client_fixture(mocker): @pytest.fixture(name="test_request") -def test_request_fixture(): +def test_request_fixture() -> Request: """Create a test FastAPI Request object with proper scope.""" return Request( scope={ @@ -43,7 +46,7 @@ def test_request_fixture(): @pytest.fixture(name="test_auth") -async def test_auth_fixture(test_request): +async def test_auth_fixture(test_request: Request) -> tuple[str, str, bool, str]: """Create authentication using real noop auth module. This uses the actual NoopAuthDependency instead of mocking, @@ -55,8 +58,11 @@ async def test_auth_fixture(test_request): @pytest.mark.asyncio async def test_info_endpoint_returns_service_information( - test_config, mock_llama_stack_client, test_request, test_auth -): + test_config: Generator, + mock_llama_stack_client: Generator, + test_request: Request, + test_auth: tuple[str, str, bool, str], +) -> None: """Test that info endpoint returns correct service information. This integration test verifies: @@ -88,8 +94,12 @@ async def test_info_endpoint_returns_service_information( @pytest.mark.asyncio async def test_info_endpoint_handles_connection_error( - test_config, mock_llama_stack_client, test_request, test_auth, mocker -): + test_config: Generator, + mock_llama_stack_client: Generator, + test_request: Request, + test_auth: tuple[str, str, bool, str], + mocker: MockerFixture, +) -> None: """Test that info endpoint properly handles Llama Stack connection errors. This integration test verifies: @@ -124,8 +134,11 @@ async def test_info_endpoint_handles_connection_error( @pytest.mark.asyncio async def test_info_endpoint_uses_configuration_values( - test_config, mock_llama_stack_client, test_request, test_auth -): + test_config: Generator, + mock_llama_stack_client: Generator, + test_request: Request, + test_auth: tuple[str, str, bool, str], +) -> None: """Test that info endpoint correctly uses configuration values. This integration test verifies: From 62ea9575d2d0e0bf783b74fe02a4c8283a6cf5c1 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 26 Oct 2025 16:39:56 +0100 Subject: [PATCH 3/3] Type hints in test_openapi_json.py --- tests/integration/conftest.py | 5 +++-- .../endpoints/test_info_integration.py | 21 +++++++++++-------- tests/integration/test_openapi_json.py | 6 +++--- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 50a7d5622..74f875fe2 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -5,7 +5,8 @@ from typing import Generator import pytest from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import sessionmaker, Session +from sqlalchemy.engine import Engine from configuration import configuration from models.database.base import Base @@ -69,7 +70,7 @@ def test_db_engine_fixture() -> Generator: @pytest.fixture(name="test_db_session", scope="function") -def test_db_session_fixture(test_db_engine) -> Generator: +def test_db_session_fixture(test_db_engine: Engine) -> Generator[Session, None, None]: """Create a database session for testing. Provides a real database session connected to the in-memory test database. diff --git a/tests/integration/endpoints/test_info_integration.py b/tests/integration/endpoints/test_info_integration.py index 818676b3b..3d7ead15c 100644 --- a/tests/integration/endpoints/test_info_integration.py +++ b/tests/integration/endpoints/test_info_integration.py @@ -1,20 +1,23 @@ """Integration tests for the /info endpoint.""" +from typing import Generator, Any import pytest -from typing import Generator -from pytest_mock import MockerFixture +from pytest_mock import MockerFixture, AsyncMockType from fastapi import HTTPException, Request, status from llama_stack_client import APIConnectionError from llama_stack_client.types import VersionInfo +from configuration import AppConfig from app.endpoints.info import info_endpoint_handler from authentication.noop import NoopAuthDependency from version import __version__ @pytest.fixture(name="mock_llama_stack_client") -def mock_llama_stack_client_fixture(mocker: MockerFixture) -> Generator: +def mock_llama_stack_client_fixture( + mocker: MockerFixture, +) -> Generator[Any, None, None]: """Mock only the external Llama Stack client. This is the only external dependency we mock for integration tests, @@ -58,8 +61,8 @@ async def test_auth_fixture(test_request: Request) -> tuple[str, str, bool, str] @pytest.mark.asyncio async def test_info_endpoint_returns_service_information( - test_config: Generator, - mock_llama_stack_client: Generator, + test_config: AppConfig, + mock_llama_stack_client: AsyncMockType, test_request: Request, test_auth: tuple[str, str, bool, str], ) -> None: @@ -94,8 +97,8 @@ async def test_info_endpoint_returns_service_information( @pytest.mark.asyncio async def test_info_endpoint_handles_connection_error( - test_config: Generator, - mock_llama_stack_client: Generator, + test_config: AppConfig, + mock_llama_stack_client: AsyncMockType, test_request: Request, test_auth: tuple[str, str, bool, str], mocker: MockerFixture, @@ -134,8 +137,8 @@ async def test_info_endpoint_handles_connection_error( @pytest.mark.asyncio async def test_info_endpoint_uses_configuration_values( - test_config: Generator, - mock_llama_stack_client: Generator, + test_config: AppConfig, + mock_llama_stack_client: AsyncMockType, test_request: Request, test_auth: tuple[str, str, bool, str], ) -> None: diff --git a/tests/integration/test_openapi_json.py b/tests/integration/test_openapi_json.py index 166fc00c0..6bdbdcbce 100644 --- a/tests/integration/test_openapi_json.py +++ b/tests/integration/test_openapi_json.py @@ -32,7 +32,7 @@ def open_api_spec() -> dict: return _load_openapi_spec() -def test_openapi_top_level_info(spec: dict): +def test_openapi_top_level_info(spec: dict) -> None: """Test all top level informations stored in OpenAPI specification.""" assert spec.get("openapi") == "3.1.0" @@ -48,7 +48,7 @@ def test_openapi_top_level_info(spec: dict): assert "apache.org/licenses" in (license_info.get("url") or "") -def test_servers_section_present(spec: dict): +def test_servers_section_present(spec: dict) -> None: """Test the servers section stored in OpenAPI specification.""" servers = spec.get("servers") assert isinstance(servers, list) and servers, "servers must be a non-empty list" @@ -101,7 +101,7 @@ def test_servers_section_present(spec: dict): ) def test_paths_and_responses_exist( spec: dict, path: str, method: str, expected_codes: set[str] -): +) -> None: """Tests all paths defined in OpenAPI specification.""" paths = spec.get("paths") or {} assert path in paths, f"Missing path: {path}"