From d0d2429f458544deeb6e76c821e912741c4282ce Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 19 Oct 2025 15:22:58 +0200 Subject: [PATCH 1/2] LCORE-739: type hint for mocker fixture More refactoring --- tests/unit/app/endpoints/test_config.py | 5 +- .../unit/app/endpoints/test_conversations.py | 67 ++++++++++------- .../app/endpoints/test_conversations_v2.py | 19 +++-- tests/unit/app/endpoints/test_feedback.py | 11 +-- tests/unit/app/endpoints/test_health.py | 15 ++-- tests/unit/authentication/test_k8s.py | 16 ++-- tests/unit/cache/test_cache_factory.py | 5 +- tests/unit/cache/test_postgres_cache.py | 75 +++++++++++++------ tests/unit/metrics/test_utis.py | 5 +- tests/unit/utils/auth_helpers.py | 4 +- tests/unit/utils/test_common.py | 21 ++++-- tests/unit/utils/test_endpoints.py | 23 ++++-- tests/unit/utils/test_llama_stack_version.py | 11 ++- tests/unit/utils/test_transcripts.py | 6 +- 14 files changed, 188 insertions(+), 95 deletions(-) diff --git a/tests/unit/app/endpoints/test_config.py b/tests/unit/app/endpoints/test_config.py index ac1dd31cc..05f97791e 100644 --- a/tests/unit/app/endpoints/test_config.py +++ b/tests/unit/app/endpoints/test_config.py @@ -1,6 +1,7 @@ """Unit tests for the /config REST API endpoint.""" import pytest +from pytest_mock import MockerFixture from fastapi import HTTPException, Request, status from app.endpoints.config import config_endpoint_handler @@ -9,7 +10,7 @@ @pytest.mark.asyncio -async def test_config_endpoint_handler_configuration_not_loaded(mocker): +async def test_config_endpoint_handler_configuration_not_loaded(mocker: MockerFixture): """Test the config endpoint handler.""" mock_authorization_resolvers(mocker) @@ -34,7 +35,7 @@ async def test_config_endpoint_handler_configuration_not_loaded(mocker): @pytest.mark.asyncio -async def test_config_endpoint_handler_configuration_loaded(mocker): +async def test_config_endpoint_handler_configuration_loaded(mocker: MockerFixture): """Test the config endpoint handler.""" mock_authorization_resolvers(mocker) diff --git a/tests/unit/app/endpoints/test_conversations.py b/tests/unit/app/endpoints/test_conversations.py index 42cfc7d7d..ca8899ffe 100644 --- a/tests/unit/app/endpoints/test_conversations.py +++ b/tests/unit/app/endpoints/test_conversations.py @@ -4,6 +4,7 @@ from fastapi import HTTPException, status, Request import pytest +from pytest_mock import MockerFixture from llama_stack_client import APIConnectionError, NotFoundError from app.endpoints.conversations import ( @@ -42,7 +43,7 @@ def dummy_request() -> Request: def create_mock_conversation( - mocker, + mocker: MockerFixture, conversation_id, created_at, last_message_at, @@ -65,7 +66,7 @@ def create_mock_conversation( return mock_conversation -def mock_database_session(mocker, query_result=None): +def mock_database_session(mocker: MockerFixture, query_result=None): """Helper function to mock get_session with proper context manager support.""" mock_session = mocker.Mock() if query_result is not None: @@ -266,7 +267,7 @@ class TestGetConversationEndpoint: """Test cases for the GET /conversations/{conversation_id} endpoint.""" @pytest.mark.asyncio - async def test_configuration_not_loaded(self, mocker, dummy_request): + async def test_configuration_not_loaded(self, mocker: MockerFixture, dummy_request): """Test the endpoint when configuration is not loaded.""" mock_authorization_resolvers(mocker) mocker.patch("app.endpoints.conversations.configuration", None) @@ -283,7 +284,7 @@ async def test_configuration_not_loaded(self, mocker, dummy_request): @pytest.mark.asyncio async def test_invalid_conversation_id_format( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test the endpoint with an invalid conversation ID format.""" mock_authorization_resolvers(mocker) @@ -303,7 +304,7 @@ async def test_invalid_conversation_id_format( @pytest.mark.asyncio async def test_llama_stack_connection_error( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test the endpoint when LlamaStack connection fails.""" mock_authorization_resolvers(mocker) @@ -333,7 +334,7 @@ async def test_llama_stack_connection_error( @pytest.mark.asyncio async def test_llama_stack_not_found_error( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test the endpoint when LlamaStack returns NotFoundError.""" mock_authorization_resolvers(mocker) @@ -366,7 +367,7 @@ async def test_llama_stack_not_found_error( @pytest.mark.asyncio async def test_session_retrieve_exception( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test the endpoint when session retrieval raises an exception.""" mock_authorization_resolvers(mocker) @@ -398,7 +399,11 @@ async def test_session_retrieve_exception( @pytest.mark.asyncio async def test_get_conversation_forbidden( - self, mocker, setup_configuration, dummy_request, mock_conversation + self, + mocker: MockerFixture, + setup_configuration, + dummy_request, + mock_conversation, ): """Test forbidden access when user lacks permission to read conversation.""" mocker.patch("app.endpoints.conversations.configuration", setup_configuration) @@ -443,7 +448,7 @@ async def test_get_conversation_forbidden( @pytest.mark.asyncio async def test_get_others_conversations_allowed_for_authorized_user( self, - mocker, + mocker: MockerFixture, setup_configuration, mock_conversation, dummy_request, @@ -486,7 +491,7 @@ async def test_get_others_conversations_allowed_for_authorized_user( @pytest.mark.asyncio async def test_successful_conversation_retrieval( self, - mocker, + mocker: MockerFixture, setup_configuration, mock_session_data, expected_chat_history, @@ -531,7 +536,7 @@ class TestDeleteConversationEndpoint: """Test cases for the DELETE /conversations/{conversation_id} endpoint.""" @pytest.mark.asyncio - async def test_configuration_not_loaded(self, mocker, dummy_request): + async def test_configuration_not_loaded(self, mocker: MockerFixture, dummy_request): """Test the endpoint when configuration is not loaded.""" mock_authorization_resolvers(mocker) mocker.patch("app.endpoints.conversations.configuration", None) @@ -548,7 +553,7 @@ async def test_configuration_not_loaded(self, mocker, dummy_request): @pytest.mark.asyncio async def test_invalid_conversation_id_format( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test the endpoint with an invalid conversation ID format.""" mock_authorization_resolvers(mocker) @@ -568,7 +573,7 @@ async def test_invalid_conversation_id_format( @pytest.mark.asyncio async def test_llama_stack_connection_error( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test the endpoint when LlamaStack connection fails.""" mock_authorization_resolvers(mocker) @@ -597,7 +602,7 @@ async def test_llama_stack_connection_error( @pytest.mark.asyncio async def test_llama_stack_not_found_error( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test the endpoint when LlamaStack returns NotFoundError.""" mock_authorization_resolvers(mocker) @@ -630,7 +635,7 @@ async def test_llama_stack_not_found_error( @pytest.mark.asyncio async def test_session_deletion_exception( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test the endpoint when session deletion raises an exception.""" mock_authorization_resolvers(mocker) @@ -665,7 +670,11 @@ async def test_session_deletion_exception( @pytest.mark.asyncio async def test_delete_conversation_forbidden( - self, mocker, setup_configuration, dummy_request, mock_conversation + self, + mocker: MockerFixture, + setup_configuration, + dummy_request, + mock_conversation, ): """Test forbidden deletion when user lacks permission to delete conversation.""" mocker.patch("app.endpoints.conversations.configuration", setup_configuration) @@ -709,7 +718,11 @@ async def test_delete_conversation_forbidden( @pytest.mark.asyncio async def test_delete_others_conversations_allowed_for_authorized_user( - self, mocker, setup_configuration, mock_conversation, dummy_request + self, + mocker: MockerFixture, + setup_configuration, + mock_conversation, + dummy_request, ): """Test allowed deletion of another user's conversation for authorized user.""" mocker.patch( @@ -752,7 +765,7 @@ async def test_delete_others_conversations_allowed_for_authorized_user( @pytest.mark.asyncio async def test_successful_conversation_deletion( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test successful conversation deletion.""" mock_authorization_resolvers(mocker) @@ -794,7 +807,7 @@ class TestGetConversationsListEndpoint: """Test cases for the GET /conversations endpoint.""" @pytest.mark.asyncio - async def test_configuration_not_loaded(self, mocker, dummy_request): + async def test_configuration_not_loaded(self, mocker: MockerFixture, dummy_request): """Test the endpoint when configuration is not loaded.""" mock_authorization_resolvers(mocker) mocker.patch("app.endpoints.conversations.configuration", None) @@ -809,7 +822,7 @@ async def test_configuration_not_loaded(self, mocker, dummy_request): @pytest.mark.asyncio async def test_successful_conversations_list_retrieval( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test successful retrieval of conversations list.""" mock_authorization_resolvers(mocker) @@ -869,7 +882,7 @@ async def test_successful_conversations_list_retrieval( @pytest.mark.asyncio async def test_empty_conversations_list( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test when user has no conversations.""" mock_authorization_resolvers(mocker) @@ -887,7 +900,9 @@ async def test_empty_conversations_list( assert response.conversations == [] @pytest.mark.asyncio - async def test_database_exception(self, mocker, setup_configuration, dummy_request): + async def test_database_exception( + self, mocker: MockerFixture, setup_configuration, dummy_request + ): """Test when database query raises an exception.""" mock_authorization_resolvers(mocker) mocker.patch("app.endpoints.conversations.configuration", setup_configuration) @@ -906,7 +921,7 @@ async def test_database_exception(self, mocker, setup_configuration, dummy_reque @pytest.mark.asyncio async def test_conversations_list_with_none_topic_summary( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test conversations list when topic_summary is None.""" mock_authorization_resolvers(mocker) @@ -940,7 +955,7 @@ async def test_conversations_list_with_none_topic_summary( @pytest.mark.asyncio async def test_conversations_list_with_mixed_topic_summaries( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test conversations list with mixed topic_summary values (some None, some not).""" mock_authorization_resolvers(mocker) @@ -1005,7 +1020,7 @@ async def test_conversations_list_with_mixed_topic_summaries( @pytest.mark.asyncio async def test_conversations_list_with_empty_topic_summary( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test conversations list when topic_summary is an empty string.""" mock_authorization_resolvers(mocker) @@ -1039,7 +1054,7 @@ async def test_conversations_list_with_empty_topic_summary( @pytest.mark.asyncio async def test_conversations_list_topic_summary_field_presence( - self, mocker, setup_configuration, dummy_request + self, mocker: MockerFixture, setup_configuration, dummy_request ): """Test that topic_summary field is always present in ConversationDetails objects.""" mock_authorization_resolvers(mocker) diff --git a/tests/unit/app/endpoints/test_conversations_v2.py b/tests/unit/app/endpoints/test_conversations_v2.py index 0448c2206..cc4ee80a5 100644 --- a/tests/unit/app/endpoints/test_conversations_v2.py +++ b/tests/unit/app/endpoints/test_conversations_v2.py @@ -4,6 +4,7 @@ from unittest.mock import Mock import pytest +from pytest_mock import MockerFixture from fastapi import HTTPException, status from app.endpoints.conversations_v2 import ( @@ -71,13 +72,13 @@ def mock_configuration(): class TestCheckValidConversationId: """Test cases for the check_valid_conversation_id function.""" - def test_valid_conversation_id(self, mocker): + def test_valid_conversation_id(self, mocker: MockerFixture): """Test with a valid conversation ID.""" mocker.patch("app.endpoints.conversations_v2.check_suid", return_value=True) # Should not raise an exception check_valid_conversation_id(VALID_CONVERSATION_ID) - def test_invalid_conversation_id(self, mocker): + def test_invalid_conversation_id(self, mocker: MockerFixture): """Test with an invalid conversation ID.""" mocker.patch("app.endpoints.conversations_v2.check_suid", return_value=False) @@ -117,7 +118,7 @@ class TestUpdateConversationEndpoint: """Test cases for the PUT /conversations/{conversation_id} endpoint.""" @pytest.mark.asyncio - async def test_configuration_not_loaded(self, mocker): + async def test_configuration_not_loaded(self, mocker: MockerFixture): """Test the endpoint when configuration is not loaded.""" mock_authorization_resolvers(mocker) mocker.patch("app.endpoints.conversations_v2.configuration", None) @@ -134,7 +135,9 @@ async def test_configuration_not_loaded(self, mocker): assert exc_info.value.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR @pytest.mark.asyncio - async def test_invalid_conversation_id_format(self, mocker, mock_configuration): + async def test_invalid_conversation_id_format( + self, mocker: MockerFixture, mock_configuration + ): """Test the endpoint with an invalid conversation ID format.""" mock_authorization_resolvers(mocker) mocker.patch("app.endpoints.conversations_v2.configuration", mock_configuration) @@ -153,7 +156,7 @@ async def test_invalid_conversation_id_format(self, mocker, mock_configuration): assert "Invalid conversation ID format" in exc_info.value.detail["response"] @pytest.mark.asyncio - async def test_conversation_cache_not_configured(self, mocker): + async def test_conversation_cache_not_configured(self, mocker: MockerFixture): """Test the endpoint when conversation cache is not configured.""" mock_authorization_resolvers(mocker) mock_config = Mock() @@ -176,7 +179,9 @@ async def test_conversation_cache_not_configured(self, mocker): ) @pytest.mark.asyncio - async def test_conversation_not_found(self, mocker, mock_configuration): + async def test_conversation_not_found( + self, mocker: MockerFixture, mock_configuration + ): """Test the endpoint when conversation does not exist.""" mock_authorization_resolvers(mocker) mocker.patch("app.endpoints.conversations_v2.configuration", mock_configuration) @@ -196,7 +201,7 @@ async def test_conversation_not_found(self, mocker, mock_configuration): assert "Conversation not found" in exc_info.value.detail["response"] @pytest.mark.asyncio - async def test_successful_update(self, mocker, mock_configuration): + async def test_successful_update(self, mocker: MockerFixture, mock_configuration): """Test successful topic summary update.""" mock_authorization_resolvers(mocker) mocker.patch("app.endpoints.conversations_v2.configuration", mock_configuration) diff --git a/tests/unit/app/endpoints/test_feedback.py b/tests/unit/app/endpoints/test_feedback.py index 1f13b0310..9d3578c94 100644 --- a/tests/unit/app/endpoints/test_feedback.py +++ b/tests/unit/app/endpoints/test_feedback.py @@ -2,6 +2,7 @@ from fastapi import HTTPException, status import pytest +from pytest_mock import MockerFixture from configuration import configuration from app.endpoints.feedback import ( @@ -27,7 +28,7 @@ def test_is_feedback_disabled(): assert is_feedback_enabled() is False, "Feedback should be disabled" -async def test_assert_feedback_enabled_disabled(mocker): +async def test_assert_feedback_enabled_disabled(mocker: MockerFixture): """Test that assert_feedback_enabled raises HTTPException when feedback is disabled.""" # Simulate feedback being disabled @@ -40,7 +41,7 @@ async def test_assert_feedback_enabled_disabled(mocker): assert exc_info.value.detail == "Forbidden: Feedback is disabled" -async def test_assert_feedback_enabled(mocker): +async def test_assert_feedback_enabled(mocker: MockerFixture): """Test that assert_feedback_enabled does not raise an exception when feedback is enabled.""" # Simulate feedback being enabled @@ -90,7 +91,7 @@ async def test_feedback_endpoint_handler(mocker, feedback_request_data): @pytest.mark.asyncio -async def test_feedback_endpoint_handler_error(mocker): +async def test_feedback_endpoint_handler_error(mocker: MockerFixture): """Test that feedback_endpoint_handler raises an HTTPException on error.""" mock_authorization_resolvers(mocker) @@ -197,7 +198,7 @@ def test_store_feedback_on_io_error(mocker, feedback_request_data): store_feedback(user_id, feedback_request_data) -async def test_update_feedback_status_different(mocker): +async def test_update_feedback_status_different(mocker: MockerFixture): """Test that update_feedback_status returns the correct status with an update.""" configuration.user_data_collection_configuration.feedback_enabled = True @@ -214,7 +215,7 @@ async def test_update_feedback_status_different(mocker): } -async def test_update_feedback_status_no_change(mocker): +async def test_update_feedback_status_no_change(mocker: MockerFixture): """Test that update_feedback_status returns the correct status with no update.""" configuration.user_data_collection_configuration.feedback_enabled = True diff --git a/tests/unit/app/endpoints/test_health.py b/tests/unit/app/endpoints/test_health.py index 6e435adf6..d3ec8f492 100644 --- a/tests/unit/app/endpoints/test_health.py +++ b/tests/unit/app/endpoints/test_health.py @@ -3,6 +3,7 @@ from unittest.mock import Mock import pytest +from pytest_mock import MockerFixture from llama_stack.providers.datatypes import HealthStatus from app.endpoints.health import ( readiness_probe_get_method, @@ -14,7 +15,7 @@ @pytest.mark.asyncio -async def test_readiness_probe_fails_due_to_unhealthy_providers(mocker): +async def test_readiness_probe_fails_due_to_unhealthy_providers(mocker: MockerFixture): """Test the readiness endpoint handler fails when providers are unhealthy.""" mock_authorization_resolvers(mocker) @@ -43,7 +44,9 @@ async def test_readiness_probe_fails_due_to_unhealthy_providers(mocker): @pytest.mark.asyncio -async def test_readiness_probe_success_when_all_providers_healthy(mocker): +async def test_readiness_probe_success_when_all_providers_healthy( + mocker: MockerFixture, +): """Test the readiness endpoint handler succeeds when all providers are healthy.""" mock_authorization_resolvers(mocker) @@ -78,7 +81,7 @@ async def test_readiness_probe_success_when_all_providers_healthy(mocker): @pytest.mark.asyncio -async def test_liveness_probe(mocker): +async def test_liveness_probe(mocker: MockerFixture): """Test the liveness endpoint handler.""" mock_authorization_resolvers(mocker) @@ -111,7 +114,7 @@ def test_provider_health_status_optional_fields(self): class TestGetProvidersHealthStatuses: """Test cases for the get_providers_health_statuses function.""" - async def test_get_providers_health_statuses(self, mocker): + async def test_get_providers_health_statuses(self, mocker: MockerFixture): """Test get_providers_health_statuses with healthy providers.""" # Mock the imports mock_lsc = mocker.patch("client.AsyncLlamaStackClientHolder.get_client") @@ -162,7 +165,9 @@ async def test_get_providers_health_statuses(self, mocker): assert result[2].status == HealthStatus.ERROR.value assert result[2].message == "Connection failed" - async def test_get_providers_health_statuses_connection_error(self, mocker): + async def test_get_providers_health_statuses_connection_error( + self, mocker: MockerFixture + ): """Test get_providers_health_statuses when connection fails.""" # Mock the imports mock_lsc = mocker.patch("client.AsyncLlamaStackClientHolder.get_client") diff --git a/tests/unit/authentication/test_k8s.py b/tests/unit/authentication/test_k8s.py index b63ff5fe2..fd0efcb7d 100644 --- a/tests/unit/authentication/test_k8s.py +++ b/tests/unit/authentication/test_k8s.py @@ -5,6 +5,8 @@ import os import pytest +from pytest_mock import MockerFixture + from fastapi import HTTPException, Request from kubernetes.client import AuthenticationV1Api, AuthorizationV1Api from kubernetes.client.rest import ApiException @@ -70,7 +72,7 @@ def test_singleton_pattern(): assert k1 is k2 -async def test_auth_dependency_valid_token(mocker): +async def test_auth_dependency_valid_token(mocker: MockerFixture): """Tests the auth dependency with a mocked valid-token.""" dependency = K8SAuthDependency() @@ -103,7 +105,7 @@ async def test_auth_dependency_valid_token(mocker): assert token == "valid-token" -async def test_auth_dependency_invalid_token(mocker): +async def test_auth_dependency_invalid_token(mocker: MockerFixture): """Test the auth dependency with a mocked invalid-token.""" dependency = K8SAuthDependency() @@ -135,7 +137,7 @@ async def test_auth_dependency_invalid_token(mocker): assert exc_info.value.status_code == 403 -async def test_cluster_id_is_used_for_kube_admin(mocker): +async def test_cluster_id_is_used_for_kube_admin(mocker: MockerFixture): """Test the cluster id is used as user_id when user is kube:admin.""" dependency = K8SAuthDependency() mock_authz_api = mocker.patch("authentication.k8s.K8sClientSingleton.get_authz_api") @@ -175,7 +177,7 @@ async def test_cluster_id_is_used_for_kube_admin(mocker): assert token == "valid-token" -def test_auth_dependency_config(mocker): +def test_auth_dependency_config(mocker: MockerFixture): """Test the auth dependency can load kubeconfig file.""" mocker.patch.dict(os.environ, {"MY_ENV_VAR": "mocked"}) @@ -189,7 +191,7 @@ def test_auth_dependency_config(mocker): ), "authz_client is not an instance of AuthorizationV1Api" -def test_get_cluster_id(mocker): +def test_get_cluster_id(mocker: MockerFixture): """Test get_cluster_id function.""" mock_get_custom_objects_api = mocker.patch( "authentication.k8s.K8sClientSingleton.get_custom_objects_api" @@ -228,7 +230,7 @@ def test_get_cluster_id(mocker): K8sClientSingleton._get_cluster_id() -def test_get_cluster_id_in_cluster(mocker): +def test_get_cluster_id_in_cluster(mocker: MockerFixture): """Test get_cluster_id function when running inside of cluster.""" mocker.patch("authentication.k8s.RUNNING_IN_CLUSTER", True) mocker.patch("authentication.k8s.K8sClientSingleton.__new__") @@ -240,7 +242,7 @@ def test_get_cluster_id_in_cluster(mocker): assert K8sClientSingleton.get_cluster_id() == "some-cluster-id" -def test_get_cluster_id_outside_of_cluster(mocker): +def test_get_cluster_id_outside_of_cluster(mocker: MockerFixture): """Test get_cluster_id function when running outside of cluster.""" mocker.patch("authentication.k8s.RUNNING_IN_CLUSTER", False) mocker.patch("authentication.k8s.K8sClientSingleton.__new__") diff --git a/tests/unit/cache/test_cache_factory.py b/tests/unit/cache/test_cache_factory.py index 611953f15..050542907 100644 --- a/tests/unit/cache/test_cache_factory.py +++ b/tests/unit/cache/test_cache_factory.py @@ -1,6 +1,7 @@ """Unit tests for CacheFactory class.""" import pytest +from pytest_mock import MockerFixture from constants import ( CACHE_TYPE_NOOP, @@ -112,7 +113,9 @@ def test_conversation_cache_sqlite_improper_config(tmpdir): _ = CacheFactory.conversation_cache(cc) -def test_conversation_cache_postgres(postgres_cache_config_fixture, mocker): +def test_conversation_cache_postgres( + postgres_cache_config_fixture, mocker: MockerFixture +): """Check if PostgreSQL is returned by factory with proper configuration.""" mocker.patch("psycopg2.connect") cache = CacheFactory.conversation_cache(postgres_cache_config_fixture) diff --git a/tests/unit/cache/test_postgres_cache.py b/tests/unit/cache/test_postgres_cache.py index 32646997d..248ed381f 100644 --- a/tests/unit/cache/test_postgres_cache.py +++ b/tests/unit/cache/test_postgres_cache.py @@ -1,6 +1,7 @@ """Unit tests for PostgreSQL cache implementation.""" import pytest +from pytest_mock import MockerFixture import psycopg2 @@ -69,7 +70,7 @@ def postgres_cache_config(): ) -def test_cache_initialization(postgres_cache_config_fixture, mocker): +def test_cache_initialization(postgres_cache_config_fixture, mocker: MockerFixture): """Test the get operation when DB is connected.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -80,7 +81,9 @@ def test_cache_initialization(postgres_cache_config_fixture, mocker): assert cache.connection is not None -def test_cache_initialization_on_error(postgres_cache_config_fixture, mocker): +def test_cache_initialization_on_error( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the get operation when DB is not connected.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect", side_effect=Exception("foo")) @@ -90,7 +93,9 @@ def test_cache_initialization_on_error(postgres_cache_config_fixture, mocker): _ = PostgresCache(postgres_cache_config_fixture) -def test_cache_initialization_connect_finalizer(postgres_cache_config_fixture, mocker): +def test_cache_initialization_connect_finalizer( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the get operation when DB is not connected.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -106,7 +111,7 @@ def test_cache_initialization_connect_finalizer(postgres_cache_config_fixture, m _ = PostgresCache(postgres_cache_config_fixture) -def test_connected_when_connected(postgres_cache_config_fixture, mocker): +def test_connected_when_connected(postgres_cache_config_fixture, mocker: MockerFixture): """Test the connected() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -116,7 +121,9 @@ def test_connected_when_connected(postgres_cache_config_fixture, mocker): assert cache.connected() is True -def test_connected_when_disconnected(postgres_cache_config_fixture, mocker): +def test_connected_when_disconnected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the connected() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -128,7 +135,9 @@ def test_connected_when_disconnected(postgres_cache_config_fixture, mocker): assert cache.connected() is False -def test_connected_when_connection_error(postgres_cache_config_fixture, mocker): +def test_connected_when_connection_error( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the connected() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -139,7 +148,9 @@ def test_connected_when_connection_error(postgres_cache_config_fixture, mocker): assert cache.connected() is False -def test_initialize_cache_when_connected(postgres_cache_config_fixture, mocker): +def test_initialize_cache_when_connected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the initialize_cache().""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -148,7 +159,9 @@ def test_initialize_cache_when_connected(postgres_cache_config_fixture, mocker): cache.initialize_cache() -def test_initialize_cache_when_disconnected(postgres_cache_config_fixture, mocker): +def test_initialize_cache_when_disconnected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the initialize_cache().""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -159,7 +172,7 @@ def test_initialize_cache_when_disconnected(postgres_cache_config_fixture, mocke cache.initialize_cache() -def test_ready_method(postgres_cache_config_fixture, mocker): +def test_ready_method(postgres_cache_config_fixture, mocker: MockerFixture): """Test the ready() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -170,7 +183,9 @@ def test_ready_method(postgres_cache_config_fixture, mocker): assert ready is True -def test_get_operation_when_disconnected(postgres_cache_config_fixture, mocker): +def test_get_operation_when_disconnected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the get() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -184,7 +199,9 @@ def test_get_operation_when_disconnected(postgres_cache_config_fixture, mocker): cache.get(USER_ID_1, CONVERSATION_ID_1, False) -def test_get_operation_when_connected(postgres_cache_config_fixture, mocker): +def test_get_operation_when_connected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the get() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -203,7 +220,9 @@ def test_get_operation_returned_values(): # Need to mock the cursor.execute() method -def test_insert_or_append_when_disconnected(postgres_cache_config_fixture, mocker): +def test_insert_or_append_when_disconnected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the insert_or_append() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -217,7 +236,7 @@ def test_insert_or_append_when_disconnected(postgres_cache_config_fixture, mocke def test_insert_or_append_operation_when_connected( - postgres_cache_config_fixture, mocker + postgres_cache_config_fixture, mocker: MockerFixture ): """Test the insert_or_append() method.""" # prevent real connection to PG instance @@ -229,7 +248,7 @@ def test_insert_or_append_operation_when_connected( def test_insert_or_append_operation_operation_error( - postgres_cache_config_fixture, mocker + postgres_cache_config_fixture, mocker: MockerFixture ): """Test the insert_or_append() method.""" # prevent real connection to PG instance @@ -244,7 +263,7 @@ def test_insert_or_append_operation_operation_error( cache.insert_or_append(USER_ID_1, CONVERSATION_ID_1, cache_entry_1, False) -def test_delete_when_disconnected(postgres_cache_config_fixture, mocker): +def test_delete_when_disconnected(postgres_cache_config_fixture, mocker: MockerFixture): """Test the delete() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -258,7 +277,9 @@ def test_delete_when_disconnected(postgres_cache_config_fixture, mocker): cache.delete(USER_ID_1, CONVERSATION_ID_1, False) -def test_delete_operation_when_connected(postgres_cache_config_fixture, mocker): +def test_delete_operation_when_connected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the delete() method.""" # prevent real connection to PG instance mock_connect = mocker.patch("psycopg2.connect") @@ -274,7 +295,9 @@ def test_delete_operation_when_connected(postgres_cache_config_fixture, mocker): assert cache.delete(USER_ID_1, CONVERSATION_ID_1, False) is False -def test_delete_operation_operation_error(postgres_cache_config_fixture, mocker): +def test_delete_operation_operation_error( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the delete() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -288,7 +311,9 @@ def test_delete_operation_operation_error(postgres_cache_config_fixture, mocker) cache.delete(USER_ID_1, CONVERSATION_ID_1, False) -def test_list_operation_when_disconnected(postgres_cache_config_fixture, mocker): +def test_list_operation_when_disconnected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the list() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -302,7 +327,9 @@ def test_list_operation_when_disconnected(postgres_cache_config_fixture, mocker) cache.list(USER_ID_1, False) -def test_list_operation_when_connected(postgres_cache_config_fixture, mocker): +def test_list_operation_when_connected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test the list() method.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") @@ -314,7 +341,7 @@ def test_list_operation_when_connected(postgres_cache_config_fixture, mocker): assert isinstance(lst, list) -def test_topic_summary_operations(postgres_cache_config_fixture, mocker): +def test_topic_summary_operations(postgres_cache_config_fixture, mocker: MockerFixture): """Test topic summary set operations and retrieval via list.""" # prevent real connection to PG instance mock_connect = mocker.patch("psycopg2.connect") @@ -343,7 +370,9 @@ def test_topic_summary_operations(postgres_cache_config_fixture, mocker): assert isinstance(conversations[0], ConversationData) -def test_topic_summary_after_conversation_delete(postgres_cache_config_fixture, mocker): +def test_topic_summary_after_conversation_delete( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test that topic summary is deleted when conversation is deleted.""" # prevent real connection to PG instance mock_connect = mocker.patch("psycopg2.connect") @@ -364,7 +393,9 @@ def test_topic_summary_after_conversation_delete(postgres_cache_config_fixture, assert deleted is True -def test_topic_summary_when_disconnected(postgres_cache_config_fixture, mocker): +def test_topic_summary_when_disconnected( + postgres_cache_config_fixture, mocker: MockerFixture +): """Test topic summary operations when cache is disconnected.""" # prevent real connection to PG instance mocker.patch("psycopg2.connect") diff --git a/tests/unit/metrics/test_utis.py b/tests/unit/metrics/test_utis.py index 9b2a131ba..be1338f59 100644 --- a/tests/unit/metrics/test_utis.py +++ b/tests/unit/metrics/test_utis.py @@ -1,9 +1,10 @@ """Unit tests for functions defined in metrics/utils.py""" +from pytest_mock import MockerFixture from metrics.utils import setup_model_metrics, update_llm_token_count_from_turn -async def test_setup_model_metrics(mocker) -> None: +async def test_setup_model_metrics(mocker: MockerFixture) -> None: """Test the setup_model_metrics function.""" # Mock the LlamaStackAsLibraryClient @@ -76,7 +77,7 @@ async def test_setup_model_metrics(mocker) -> None: ) -def test_update_llm_token_count_from_turn(mocker) -> None: +def test_update_llm_token_count_from_turn(mocker: MockerFixture) -> None: """Test the update_llm_token_count_from_turn function.""" mocker.patch("metrics.utils.Tokenizer.get_instance") mock_formatter_class = mocker.patch("metrics.utils.ChatFormat") diff --git a/tests/unit/utils/auth_helpers.py b/tests/unit/utils/auth_helpers.py index 77770c3a8..c569b970e 100644 --- a/tests/unit/utils/auth_helpers.py +++ b/tests/unit/utils/auth_helpers.py @@ -1,12 +1,12 @@ """Helper functions for mocking authorization in tests.""" -from typing import Any from unittest.mock import AsyncMock, Mock +from pytest_mock import MockerFixture from models.config import Action -def mock_authorization_resolvers(mocker: Any) -> None: +def mock_authorization_resolvers(mocker: MockerFixture) -> None: """Mock authorization resolvers to allow all access. This function mocks the authorization middleware to bypass authorization diff --git a/tests/unit/utils/test_common.py b/tests/unit/utils/test_common.py index 6a5e3a390..353b8a18b 100644 --- a/tests/unit/utils/test_common.py +++ b/tests/unit/utils/test_common.py @@ -2,6 +2,7 @@ from unittest.mock import Mock, AsyncMock from logging import Logger +from pytest_mock import MockerFixture import pytest @@ -18,7 +19,7 @@ @pytest.mark.asyncio -async def test_register_mcp_servers_empty_list(mocker) -> None: +async def test_register_mcp_servers_empty_list(mocker: MockerFixture) -> None: """Test register_mcp_servers with empty MCP servers list.""" # Mock the logger mock_logger = Mock(spec=Logger) @@ -49,7 +50,9 @@ async def test_register_mcp_servers_empty_list(mocker) -> None: @pytest.mark.asyncio -async def test_register_mcp_servers_single_server_not_registered(mocker) -> None: +async def test_register_mcp_servers_single_server_not_registered( + mocker: MockerFixture, +) -> None: """Test register_mcp_servers with single MCP server that is not yet registered.""" # Mock the logger mock_logger = Mock(spec=Logger) @@ -94,7 +97,9 @@ async def test_register_mcp_servers_single_server_not_registered(mocker) -> None @pytest.mark.asyncio -async def test_register_mcp_servers_single_server_already_registered(mocker) -> None: +async def test_register_mcp_servers_single_server_already_registered( + mocker: MockerFixture, +) -> None: """Test register_mcp_servers with single MCP server that is already registered.""" # Mock the logger mock_logger = Mock(spec=Logger) @@ -132,7 +137,9 @@ async def test_register_mcp_servers_single_server_already_registered(mocker) -> @pytest.mark.asyncio -async def test_register_mcp_servers_multiple_servers_mixed_registration(mocker) -> None: +async def test_register_mcp_servers_multiple_servers_mixed_registration( + mocker: MockerFixture, +) -> None: """Test register_mcp_servers with multiple MCP servers - some registered, some not.""" # Mock the logger mock_logger = Mock(spec=Logger) @@ -194,7 +201,7 @@ async def test_register_mcp_servers_multiple_servers_mixed_registration(mocker) @pytest.mark.asyncio -async def test_register_mcp_servers_with_custom_provider(mocker) -> None: +async def test_register_mcp_servers_with_custom_provider(mocker: MockerFixture) -> None: """Test register_mcp_servers with MCP server using custom provider.""" # Mock the logger mock_logger = Mock(spec=Logger) @@ -235,7 +242,9 @@ async def test_register_mcp_servers_with_custom_provider(mocker) -> None: @pytest.mark.asyncio -async def test_register_mcp_servers_async_with_library_client(mocker) -> None: +async def test_register_mcp_servers_async_with_library_client( + mocker: MockerFixture, +) -> None: """ Test that `register_mcp_servers_async` correctly registers MCP servers when using the library client configuration. diff --git a/tests/unit/utils/test_endpoints.py b/tests/unit/utils/test_endpoints.py index d8b31cc34..1f1ff5b31 100644 --- a/tests/unit/utils/test_endpoints.py +++ b/tests/unit/utils/test_endpoints.py @@ -1,7 +1,10 @@ """Unit tests for endpoints utility functions.""" +# pylint: disable=too-many-lines + import os import pytest +from pytest_mock import MockerFixture from fastapi import HTTPException from pydantic import AnyUrl @@ -245,7 +248,9 @@ def test_get_profile_prompt_with_enabled_query_system_prompt( @pytest.mark.asyncio -async def test_get_agent_with_conversation_id(prepare_agent_mocks, mocker): +async def test_get_agent_with_conversation_id( + prepare_agent_mocks, mocker: MockerFixture +): """Test get_agent function when agent exists in llama stack.""" mock_client, mock_agent = prepare_agent_mocks conversation_id = "test_conversation_id" @@ -664,7 +669,9 @@ async def test_get_agent_no_tools_false_preserves_parser( @pytest.mark.asyncio -async def test_get_temp_agent_basic_functionality(prepare_agent_mocks, mocker): +async def test_get_temp_agent_basic_functionality( + prepare_agent_mocks, mocker: MockerFixture +): """Test get_temp_agent function creates agent with correct parameters.""" mock_client, mock_agent = prepare_agent_mocks mock_agent.create_session.return_value = "temp_session_id" @@ -703,7 +710,9 @@ async def test_get_temp_agent_basic_functionality(prepare_agent_mocks, mocker): @pytest.mark.asyncio -async def test_get_temp_agent_returns_valid_ids(prepare_agent_mocks, mocker): +async def test_get_temp_agent_returns_valid_ids( + prepare_agent_mocks, mocker: MockerFixture +): """Test get_temp_agent function returns valid agent_id and session_id.""" mock_client, mock_agent = prepare_agent_mocks mock_agent.agent_id = "generated_agent_id" @@ -736,7 +745,9 @@ async def test_get_temp_agent_returns_valid_ids(prepare_agent_mocks, mocker): @pytest.mark.asyncio -async def test_get_temp_agent_no_persistence(prepare_agent_mocks, mocker): +async def test_get_temp_agent_no_persistence( + prepare_agent_mocks, mocker: MockerFixture +): """Test get_temp_agent function creates agent without session persistence.""" mock_client, mock_agent = prepare_agent_mocks mock_agent.create_session.return_value = "temp_session_id" @@ -818,7 +829,9 @@ def test_get_topic_summary_system_prompt_with_custom_profile(): assert topic_summary_prompt == prompts.get("topic_summary") -def test_get_topic_summary_system_prompt_with_custom_profile_no_topic_summary(mocker): +def test_get_topic_summary_system_prompt_with_custom_profile_no_topic_summary( + mocker: MockerFixture, +): """Test that default topic summary prompt is returned when custom profile has no topic_summary prompt. """ diff --git a/tests/unit/utils/test_llama_stack_version.py b/tests/unit/utils/test_llama_stack_version.py index a2ca92806..a6fa9a7d1 100644 --- a/tests/unit/utils/test_llama_stack_version.py +++ b/tests/unit/utils/test_llama_stack_version.py @@ -2,6 +2,7 @@ import pytest from semver import Version +from pytest_mock import MockerFixture from llama_stack_client.types import VersionInfo @@ -17,7 +18,9 @@ @pytest.mark.asyncio -async def test_check_llama_stack_version_minimal_supported_version(mocker): +async def test_check_llama_stack_version_minimal_supported_version( + mocker: MockerFixture, +): """Test the check_llama_stack_version function.""" # mock the Llama Stack client @@ -31,7 +34,9 @@ async def test_check_llama_stack_version_minimal_supported_version(mocker): @pytest.mark.asyncio -async def test_check_llama_stack_version_maximal_supported_version(mocker): +async def test_check_llama_stack_version_maximal_supported_version( + mocker: MockerFixture, +): """Test the check_llama_stack_version function.""" # mock the Llama Stack client @@ -45,7 +50,7 @@ async def test_check_llama_stack_version_maximal_supported_version(mocker): @pytest.mark.asyncio -async def test_check_llama_stack_version_too_small_version(mocker): +async def test_check_llama_stack_version_too_small_version(mocker: MockerFixture): """Test the check_llama_stack_version function.""" # mock the Llama Stack client diff --git a/tests/unit/utils/test_transcripts.py b/tests/unit/utils/test_transcripts.py index 0569927d5..918bfe00c 100644 --- a/tests/unit/utils/test_transcripts.py +++ b/tests/unit/utils/test_transcripts.py @@ -1,6 +1,8 @@ """Unit tests for functions defined in utils.transcripts module.""" import hashlib +from pytest_mock import MockerFixture + from configuration import AppConfig from models.requests import QueryRequest @@ -11,7 +13,7 @@ from utils.types import ToolCallSummary, TurnSummary -def test_construct_transcripts_path(mocker): +def test_construct_transcripts_path(mocker: MockerFixture): """Test the construct_transcripts_path function.""" config_dict = { @@ -50,7 +52,7 @@ def test_construct_transcripts_path(mocker): ), "Path should be constructed correctly" -def test_store_transcript(mocker): +def test_store_transcript(mocker: MockerFixture): """Test the store_transcript function.""" mocker.patch("builtins.open", mocker.mock_open()) From bfc678712bc35ce6381bb8f26ef3e73bf7d8e0a1 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 19 Oct 2025 15:42:10 +0200 Subject: [PATCH 2/2] More changes --- tests/unit/app/test_database.py | 34 ++++++++++++++++++------------ tests/unit/utils/test_endpoints.py | 14 ++++++------ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/tests/unit/app/test_database.py b/tests/unit/app/test_database.py index 5b7e1ee03..d8ce1103c 100644 --- a/tests/unit/app/test_database.py +++ b/tests/unit/app/test_database.py @@ -5,6 +5,7 @@ from pathlib import Path import tempfile import pytest +from pytest_mock import MockerFixture from sqlalchemy.engine.base import Engine from sqlalchemy.orm import Session @@ -46,7 +47,7 @@ def base_postgres_config_fixture(): class TestGetEngine: """Test cases for get_engine function.""" - def test_get_engine_when_initialized(self, mocker): + def test_get_engine_when_initialized(self, mocker: MockerFixture): """Test get_engine returns engine when initialized.""" mock_engine = mocker.MagicMock(spec=Engine) database.engine = mock_engine @@ -67,7 +68,7 @@ def test_get_engine_when_not_initialized(self): class TestGetSession: """Test cases for get_session function.""" - def test_get_session_when_initialized(self, mocker): + def test_get_session_when_initialized(self, mocker: MockerFixture): """Test get_session returns session when initialized.""" mock_session_local = mocker.MagicMock() mock_session = mocker.MagicMock(spec=Session) @@ -90,7 +91,7 @@ def test_get_session_when_not_initialized(self): class TestCreateTables: """Test cases for create_tables function.""" - def test_create_tables_success(self, mocker): + def test_create_tables_success(self, mocker: MockerFixture): """Test create_tables calls Base.metadata.create_all with engine.""" mock_base = mocker.patch("app.database.Base") mock_get_engine = mocker.patch("app.database.get_engine") @@ -102,7 +103,7 @@ def test_create_tables_success(self, mocker): mock_get_engine.assert_called_once() mock_base.metadata.create_all.assert_called_once_with(mock_engine) - def test_create_tables_when_engine_not_initialized(self, mocker): + def test_create_tables_when_engine_not_initialized(self, mocker: MockerFixture): """Test create_tables raises error when engine not initialized.""" mock_get_engine = mocker.patch("app.database.get_engine") mock_get_engine.side_effect = RuntimeError("Database engine not initialized") @@ -134,7 +135,7 @@ def test_create_sqlite_engine_directory_not_exists(self): ): database._create_sqlite_engine(config) - def test_create_sqlite_engine_creation_failure(self, mocker): + def test_create_sqlite_engine_creation_failure(self, mocker: MockerFixture): """Test _create_sqlite_engine handles engine creation failure.""" mock_create_engine = mocker.patch("app.database.create_engine") with tempfile.TemporaryDirectory() as temp_dir: @@ -150,7 +151,7 @@ class TestCreatePostgresEngine: """Test cases for _create_postgres_engine function.""" def test_create_postgres_engine_success_default_schema( - self, mocker, base_postgres_config + self, mocker: MockerFixture, base_postgres_config ): """Test _create_postgres_engine creates engine successfully with default schema.""" mock_create_engine = mocker.patch("app.database.create_engine") @@ -170,7 +171,7 @@ def test_create_postgres_engine_success_default_schema( assert expected_url == call_args[0][0] def test_create_postgres_engine_success_custom_schema( - self, mocker, base_postgres_config + self, mocker: MockerFixture, base_postgres_config ): """Test _create_postgres_engine creates engine successfully with custom schema.""" mock_create_engine = mocker.patch("app.database.create_engine") @@ -191,7 +192,9 @@ def test_create_postgres_engine_success_custom_schema( mock_connection.execute.assert_called_once() mock_connection.commit.assert_called_once() - def test_create_postgres_engine_with_ca_cert(self, mocker, base_postgres_config): + def test_create_postgres_engine_with_ca_cert( + self, mocker: MockerFixture, base_postgres_config + ): """Test _create_postgres_engine with CA certificate path.""" mock_create_engine = mocker.patch("app.database.create_engine") mock_engine = mocker.MagicMock(spec=Engine) @@ -209,7 +212,7 @@ def test_create_postgres_engine_with_ca_cert(self, mocker, base_postgres_config) assert call_args[1]["connect_args"]["sslrootcert"] == cert_file.name def test_create_postgres_engine_creation_failure( - self, mocker, base_postgres_config + self, mocker: MockerFixture, base_postgres_config ): """Test _create_postgres_engine handles engine creation failure.""" mock_create_engine = mocker.patch("app.database.create_engine") @@ -219,7 +222,7 @@ def test_create_postgres_engine_creation_failure( database._create_postgres_engine(base_postgres_config) def test_create_postgres_engine_schema_creation_failure( - self, mocker, base_postgres_config + self, mocker: MockerFixture, base_postgres_config ): """Test _create_postgres_engine handles schema creation failure.""" mock_create_engine = mocker.patch("app.database.create_engine") @@ -240,7 +243,12 @@ class TestInitializeDatabase: """Test cases for initialize_database function.""" def _setup_common_mocks( - self, *, mocker, mock_sessionmaker, mock_logger, enable_debug=False + self, + *, + mocker: MockerFixture, + mock_sessionmaker, + mock_logger, + enable_debug=False, ): """Setup common mocks for initialize_database tests.""" mock_engine = mocker.MagicMock(spec=Engine) @@ -261,7 +269,7 @@ def _verify_common_assertions( def test_initialize_database_sqlite( self, - mocker, + mocker: MockerFixture, ): """Test initialize_database with SQLite configuration.""" # Setup mocks @@ -295,7 +303,7 @@ def test_initialize_database_sqlite( def test_initialize_database_postgres( self, - mocker, + mocker: MockerFixture, base_postgres_config, ): """Test initialize_database with PostgreSQL configuration.""" diff --git a/tests/unit/utils/test_endpoints.py b/tests/unit/utils/test_endpoints.py index 1f1ff5b31..ef2b33a08 100644 --- a/tests/unit/utils/test_endpoints.py +++ b/tests/unit/utils/test_endpoints.py @@ -284,7 +284,7 @@ async def test_get_agent_with_conversation_id( @pytest.mark.asyncio async def test_get_agent_with_conversation_id_and_no_agent_in_llama_stack( - setup_configuration, prepare_agent_mocks, mocker + setup_configuration, prepare_agent_mocks, mocker: MockerFixture ): """Test get_agent function when conversation_id is provided.""" mock_client, mock_agent = prepare_agent_mocks @@ -342,7 +342,7 @@ async def test_get_agent_with_conversation_id_and_no_agent_in_llama_stack( @pytest.mark.asyncio async def test_get_agent_no_conversation_id( - setup_configuration, prepare_agent_mocks, mocker + setup_configuration, prepare_agent_mocks, mocker: MockerFixture ): """Test get_agent function when conversation_id is None.""" mock_client, mock_agent = prepare_agent_mocks @@ -396,7 +396,7 @@ async def test_get_agent_no_conversation_id( @pytest.mark.asyncio async def test_get_agent_empty_shields( - setup_configuration, prepare_agent_mocks, mocker + setup_configuration, prepare_agent_mocks, mocker: MockerFixture ): """Test get_agent function with empty shields list.""" mock_client, mock_agent = prepare_agent_mocks @@ -450,7 +450,7 @@ async def test_get_agent_empty_shields( @pytest.mark.asyncio async def test_get_agent_multiple_mcp_servers( - setup_configuration, prepare_agent_mocks, mocker + setup_configuration, prepare_agent_mocks, mocker: MockerFixture ): """Test get_agent function with multiple MCP servers.""" mock_client, mock_agent = prepare_agent_mocks @@ -506,7 +506,7 @@ async def test_get_agent_multiple_mcp_servers( @pytest.mark.asyncio async def test_get_agent_session_persistence_enabled( - setup_configuration, prepare_agent_mocks, mocker + setup_configuration, prepare_agent_mocks, mocker: MockerFixture ): """Test get_agent function ensures session persistence is enabled.""" mock_client, mock_agent = prepare_agent_mocks @@ -555,7 +555,7 @@ async def test_get_agent_session_persistence_enabled( @pytest.mark.asyncio async def test_get_agent_no_tools_no_parser( - setup_configuration, prepare_agent_mocks, mocker + setup_configuration, prepare_agent_mocks, mocker: MockerFixture ): """Test get_agent function sets tool_parser=None when no_tools=True.""" mock_client, mock_agent = prepare_agent_mocks @@ -610,7 +610,7 @@ async def test_get_agent_no_tools_no_parser( @pytest.mark.asyncio async def test_get_agent_no_tools_false_preserves_parser( - setup_configuration, prepare_agent_mocks, mocker + setup_configuration, prepare_agent_mocks, mocker: MockerFixture ): """Test get_agent function preserves tool_parser when no_tools=False.""" mock_client, mock_agent = prepare_agent_mocks