Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore(api): drop stale unit-test ruff per-file ignores (#44033)

Eddy ZHANGdb2330dfc0d7
diff --git a/api/tests/unit_tests/.ruff.toml b/api/tests/unit_tests/.ruff.toml
index ea3bbf23001..5751c9fa594 100644
--- a/api/tests/unit_tests/.ruff.toml
+++ b/api/tests/unit_tests/.ruff.toml
@@ -13,7 +13,6 @@ extend-select = ["ANN401", "ARG"]
"repositories/test_app_definition_query_repository_agent.py" = ["ARG005", "TID251"]
"controllers/common/test_app_access.py" = ["ARG005"]
"controllers/console/agent/test_agent_controllers.py" = ["ARG001", "ARG002", "ARG003", "ARG005", "TID251"]
-"controllers/console/app/test_agent_app_sandbox.py" = ["ARG002", "ARG005"]
"controllers/console/app/test_agent_config_inspector.py" = ["ARG005"]
"controllers/console/app/test_agent_manage_guard.py" = ["ARG001"]
"controllers/console/app/test_annotation_security.py" = ["ARG002"]
@@ -31,13 +30,9 @@ extend-select = ["ANN401", "ARG"]
"controllers/console/app/test_workflow_run_api.py" = ["ANN401", "TID251"]
"controllers/console/app/workflow_draft_variables_test.py" = ["TID251"]
"controllers/console/auth/test_account_activation.py" = ["ARG002"]
-"controllers/console/auth/test_authentication_security.py" = ["ARG002"]
-"controllers/console/auth/test_email_verification.py" = ["ARG002"]
"controllers/console/auth/test_login_logout.py" = ["ARG002"]
"controllers/console/auth/test_oauth.py" = ["ARG002"]
"controllers/console/auth/test_oauth_timezone.py" = ["ARG001"]
-"controllers/console/auth/test_password_reset.py" = ["ARG002"]
-"controllers/console/auth/test_token_refresh.py" = ["ARG002"]
"controllers/console/billing/test_billing.py" = ["ARG002"]
"controllers/console/datasets/test_datasets.py" = ["ARG005"]
"controllers/console/datasets/test_datasets_document.py" = ["ARG002", "ARG005"]
@@ -51,28 +46,21 @@ extend-select = ["ANN401", "ARG"]
"controllers/console/tag/test_tags.py" = ["ARG002"]
"controllers/console/test_files.py" = ["ARG001", "ARG002"]
"controllers/console/test_human_input_form.py" = ["ARG001", "ARG005"]
-"controllers/console/test_init_validate.py" = ["ARG005"]
-"controllers/console/test_workspace_account.py" = ["ARG002"]
"controllers/console/test_wraps.py" = ["ARG001", "ARG002"]
"controllers/console/workspace/test_load_balancing_config.py" = ["ARG001"]
"controllers/console/workspace/test_plugin.py" = ["ARG002", "TID251"]
"controllers/console/workspace/test_snippets.py" = ["ARG002"]
"controllers/console/workspace/test_tool_providers.py" = ["ARG001", "ARG005"]
"controllers/console/workspace/test_trigger_providers.py" = ["ARG001"]
-"controllers/console/workspace/test_workspace.py" = ["ARG005"]
-"controllers/files/test_tool_files.py" = ["ARG002", "ARG005"]
"controllers/inner_api/plugin/test_plugin.py" = ["ARG002"]
"controllers/inner_api/plugin/test_plugin_wraps.py" = ["ARG001", "ARG002", "ARG003", "TID251"]
"controllers/inner_api/test_runtime_credentials.py" = ["ARG001"]
"controllers/mcp/test_mcp.py" = ["ARG002"]
-"controllers/openapi/conftest.py" = ["ARG001"]
"controllers/openapi/test_account.py" = ["ARG005"]
-"controllers/openapi/test_app_describe_builder.py" = ["ARG001"]
"controllers/openapi/test_app_run_streaming.py" = ["ARG001"]
"controllers/openapi/test_contract.py" = ["ARG001", "TID251"]
"controllers/openapi/test_error_contract.py" = ["ARG002"]
"controllers/openapi/test_human_input_form.py" = ["ARG002"]
-"controllers/openapi/test_oauth_sso_claims.py" = ["ARG002"]
"controllers/openapi/test_workflow_events_openapi.py" = ["ARG002", "ARG005"]
"controllers/openapi/test_workspaces_members.py" = ["ARG001"]
"controllers/service_api/app/test_app.py" = ["ARG002"]
@@ -83,28 +71,21 @@ extend-select = ["ANN401", "ARG"]
"controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py" = ["ARG002"]
"controllers/service_api/dataset/test_dataset_segment.py" = ["ARG002"]
"controllers/service_api/dataset/test_document.py" = ["ARG001", "ARG002"]
-"controllers/service_api/dataset/test_metadata.py" = ["ARG002"]
"controllers/service_api/test_trace_session_id_parsing.py" = ["ARG001"]
"controllers/service_api/test_wraps.py" = ["ARG001", "ARG002"]
"controllers/trigger/test_trigger.py" = ["ARG002"]
"controllers/trigger/test_webhook.py" = ["ARG002"]
-"controllers/web/conftest.py" = ["ANN401", "TID251"]
"controllers/web/test_app.py" = ["ARG002", "ARG005"]
"controllers/web/test_audio.py" = ["ARG002"]
"controllers/web/test_completion.py" = ["ARG002"]
-"controllers/web/test_feature.py" = ["ARG002"]
"controllers/web/test_human_input_form.py" = ["ARG001", "ARG002", "ARG005"]
"controllers/web/test_message_endpoints.py" = ["ARG002"]
-"controllers/web/test_remote_files.py" = ["ARG002"]
-"controllers/web/test_saved_message.py" = ["ARG002"]
"controllers/web/test_web_login.py" = ["ARG002"]
-"controllers/web/test_web_passport.py" = ["ARG002"]
"controllers/web/test_workflow.py" = ["ARG002"]
"core/agent/test_base_agent_runner.py" = ["ARG002"]
"core/agent/test_cot_agent_runner.py" = ["ARG001"]
"core/agent/test_cot_chat_agent_runner.py" = ["ARG002"]
"core/agent/test_fc_agent_runner.py" = ["TID251"]
-"core/app/app_config/common/test_parameters_mapping.py" = ["ARG002"]
"core/app/app_config/easy_ui_based_app/test_dataset_manager.py" = ["ARG001", "ARG002"]
"core/app/app_config/easy_ui_based_app/test_model_config_converter.py" = ["ARG002"]
"core/app/app_config/easy_ui_based_app/test_variables_manager.py" = ["ARG002"]
@@ -201,7 +182,6 @@ extend-select = ["ANN401", "ARG"]
"core/rag/extractor/test_extract_processor.py" = ["ARG001", "ARG005"]
"core/rag/extractor/test_helpers.py" = ["ARG002"]
"core/rag/extractor/test_markdown_extractor.py" = ["ARG001"]
-"core/rag/extractor/test_notion_extractor.py" = ["ARG002", "ARG005"]
"core/rag/extractor/test_pdf_extractor.py" = ["ARG001", "ARG005"]
"core/rag/extractor/test_text_extractor.py" = ["ARG001"]
"core/rag/extractor/test_word_extractor.py" = ["ARG001", "ARG002", "ARG005"]
@@ -211,7 +191,6 @@ extend-select = ["ANN401", "ARG"]
"core/rag/indexing/processor/test_paragraph_index_processor.py" = ["ARG002", "TID251"]
"core/rag/indexing/processor/test_qa_index_processor.py" = ["ARG001", "TID251"]
"core/rag/indexing/test_index_processor.py" = ["ARG005"]
-"core/rag/indexing/test_indexing_runner.py" = ["ARG005", "TID251"]
"core/rag/pipeline/test_queue.py" = ["ARG002"]
"core/rag/retrieval/test_dataset_retrieval.py" = ["ARG001", "ARG002", "ARG005", "TID251"]
"core/rag/splitter/test_text_splitter.py" = ["ARG002", "ARG005"]
@@ -248,7 +227,6 @@ extend-select = ["ANN401", "ARG"]
"core/tools/workflow_as_tool/test_provider.py" = ["TID251"]
"core/tools/workflow_as_tool/test_tool.py" = ["ANN401", "ARG001", "ARG005", "TID251"]
"core/trigger/conftest.py" = ["ANN401", "TID251"]
-"core/trigger/debug/test_debug_event_selectors.py" = ["ARG002", "TID251"]
"core/variables/test_segment_type_validation.py" = ["TID251"]
"core/workflow/context/test_execution_context.py" = ["ANN401", "ARG002", "S110", "TID251"]
"core/workflow/context/test_flask_app_context.py" = ["ARG002"]
@@ -262,7 +240,6 @@ extend-select = ["ANN401", "ARG"]
"core/workflow/graph_engine/test_parallel_human_input_join_resume.py" = ["ARG002", "TID251"]
"core/workflow/graph_engine/test_table_runner.py" = ["ARG001", "TID251"]
"core/workflow/nodes/agent_v2/test_agent_node.py" = ["ARG001", "ARG002", "ARG005"]
-"core/workflow/nodes/agent_v2/test_ask_human_hitl.py" = ["ANN401", "TID251"]
"core/workflow/nodes/agent_v2/test_dify_tools_builder.py" = ["ANN401", "ARG001", "ARG002", "ARG005", "TID251"]
"core/workflow/nodes/agent_v2/test_output_adapter.py" = ["ARG005"]
"core/workflow/nodes/agent_v2/test_runtime_request_builder.py" = ["ARG002"]
@@ -270,7 +247,6 @@ extend-select = ["ANN401", "ARG"]
"core/workflow/nodes/http_request/test_http_request_node.py" = ["ANN401", "ARG002", "TID251"]
"core/workflow/nodes/human_input/test_entities.py" = ["TID251"]
"core/workflow/nodes/human_input/test_human_input_form_filled_event.py" = ["TID251"]
-"core/workflow/nodes/iteration/test_iteration_child_engine_errors.py" = ["ARG002", "TID251"]
"core/workflow/nodes/knowledge_index/test_knowledge_index_node.py" = ["ARG002"]
"core/workflow/nodes/knowledge_retrieval/test_knowledge_retrieval_node.py" = ["ARG002"]
"core/workflow/nodes/llm/test_node.py" = ["ARG002"]
@@ -290,8 +266,6 @@ extend-select = ["ANN401", "ARG"]
"extensions/logstore/test_sql_escape.py" = ["ARG001", "ARG002"]
"extensions/otel/decorators/handlers/test_generate_handler.py" = ["ARG001", "ARG002"]
"extensions/otel/decorators/handlers/test_workflow_app_runner_handler.py" = ["ARG001"]
-"extensions/otel/decorators/test_base.py" = ["ARG002"]
-"extensions/otel/decorators/test_handler.py" = ["ARG002"]
"extensions/otel/test_retrieval_tracing.py" = ["ARG001"]
"extensions/test_ext_request_logging.py" = ["ARG002"]
"extensions/test_redis.py" = ["ARG001"]
@@ -311,7 +285,6 @@ extend-select = ["ANN401", "ARG"]
"libs/test_smtp_client.py" = ["TID251"]
"models/test_dataset_models.py" = ["ARG005"]
"models/test_plugin_entities.py" = ["TID251"]
-"models/test_snippet.py" = ["ARG001"]
"oss/__mock/aliyun_oss.py" = ["ARG002"]
"oss/__mock/baidu_obs.py" = ["ARG002"]
"oss/__mock/base.py" = ["ARG002"]
@@ -326,13 +299,10 @@ extend-select = ["ANN401", "ARG"]
"services/agent/test_agent_services.py" = ["ARG001", "ARG002", "ARG003", "ARG005"]
"services/agent/test_composer_candidates.py" = ["ARG005"]
"services/agent/test_prompt_mentions.py" = ["ARG005"]
-"services/agent/test_skill_tool_inference_service.py" = ["ARG001", "ARG005"]
-"services/auth/test_jina_auth_standalone_module.py" = ["TID251"]
"services/controller_api.py" = ["ARG002"]
"services/data_migration/test_import_service.py" = ["ARG002", "ARG005"]
"services/dataset_service_test_helpers.py" = ["TID251"]
"services/enterprise/test_account_deletion_sync.py" = ["ARG001"]
-"services/enterprise/test_rbac_service.py" = ["ARG002"]
"services/enterprise/test_traceparent_propagation.py" = ["ARG002"]
"services/hit_service.py" = ["TID251"]
"services/plugin/test_plugin_parameter_service.py" = ["ARG002"]
@@ -349,27 +319,19 @@ extend-select = ["ANN401", "ARG"]
"services/test_api_token_service.py" = ["ARG002"]
"services/test_app_generate_service.py" = ["ARG001", "ARG002", "ARG004"]
"services/test_app_generate_service_streaming_integration.py" = ["ARG002", "TID251"]
-"services/test_archive_workflow_run_logs.py" = ["ARG002"]
"services/test_audio_service.py" = ["ARG002", "TID251"]
"services/test_batch_indexing_base.py" = ["ANN401", "TID251"]
"services/test_billing_service.py" = ["ARG001", "ARG002"]
"services/test_clear_free_plan_expired_workflow_run_logs.py" = ["ANN401", "ARG002", "ARG005", "TID251"]
"services/test_clear_free_plan_tenant_expired_logs.py" = ["ARG002", "ARG003"]
"services/test_dataset_service_document.py" = ["ARG002"]
-"services/test_dataset_service_lock_not_owned.py" = ["ARG001", "ARG005"]
"services/test_dataset_service_segment.py" = ["ARG002"]
"services/test_datasource_provider_service.py" = ["ARG002"]
"services/test_external_dataset_service.py" = ["ARG002", "TID251"]
-"services/test_feature_service_human_input_email_delivery.py" = ["ARG005"]
-"services/test_feedback_service.py" = ["ARG002"]
"services/test_human_input_delivery_test_service.py" = ["ARG005"]
-"services/test_knowledge_service.py" = ["TID251"]
"services/test_message_service.py" = ["ARG002"]
"services/test_messages_clean_service.py" = ["TID251"]
-"services/test_model_load_balancing_service.py" = ["ANN401", "ARG001", "ARG005", "TID251"]
"services/test_model_provider_service.py" = ["ANN401", "TID251"]
-"services/test_model_provider_service_sanitization.py" = ["ARG002", "ARG005"]
-"services/test_oauth_server_service.py" = ["ARG002"]
"services/test_operation_service.py" = ["TID251"]
"services/test_rag_pipeline_task_proxy.py" = ["ARG002"]
"services/test_schedule_service.py" = ["ANN401", "TID251"]
@@ -378,7 +340,6 @@ extend-select = ["ANN401", "ARG"]
"services/test_telemetry_service.py" = ["ARG001", "ARG005"]
"services/test_variable_truncator.py" = ["ARG002", "TID251"]
"services/test_variable_truncator_additional.py" = ["ANN401", "TID251"]
-"services/test_vector_service.py" = ["ARG001", "TID251"]
"services/test_webhook_service_additional.py" = ["ANN401", "ARG002", "TID251"]
"services/test_website_service.py" = ["TID251"]
"services/test_workflow_run_service.py" = ["ANN401", "ARG002", "TID251"]
@@ -390,7 +351,6 @@ extend-select = ["ANN401", "ARG"]
"services/workflow/test_workflow_converter_additional.py" = ["ANN401", "ARG001", "ARG005", "TID251"]
"services/workflow/test_workflow_event_snapshot_service.py" = ["ANN401", "ARG002", "ARG005", "TID251"]
"services/workflow/test_workflow_event_snapshot_service_additional.py" = ["ANN401", "ARG002", "ARG005", "TID251"]
-"tasks/test_agent_backend_session_cleanup_task.py" = ["ARG005"]
"tasks/test_clean_dataset_task.py" = ["ARG002"]
"tasks/test_clean_document_task.py" = ["ARG002"]
"tasks/test_dataset_indexing_task.py" = ["ARG001", "ARG002"]
diff --git a/api/tests/unit_tests/core/app/app_config/common/test_parameters_mapping.py b/api/tests/unit_tests/core/app/app_config/common/test_parameters_mapping.py
index c319a1e5b2c..fdf2cb3d85f 100644
--- a/api/tests/unit_tests/core/app/app_config/common/test_parameters_mapping.py
+++ b/api/tests/unit_tests/core/app/app_config/common/test_parameters_mapping.py
@@ -59,12 +59,11 @@ class TestGetParametersFromFeatureDict:
),
],
)
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
def test_defaults_when_key_missing(
self,
feature_key: _DefaultedFeatureKey,
expected_default: object,
- mock_config: None,
- mock_default_file_limits: int,
) -> None:
# Arrange
features = {}
@@ -79,7 +78,8 @@ class TestGetParametersFromFeatureDict:
# Assert
assert result[feature_key] == expected_default
- def test_opening_statement_present(self, mock_config: None, mock_default_file_limits: int) -> None:
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
+ def test_opening_statement_present(self) -> None:
# Arrange
features = {"opening_statement": "Hello"}
@@ -92,7 +92,8 @@ class TestGetParametersFromFeatureDict:
# Assert
assert result["opening_statement"] == "Hello"
- def test_opening_statement_missing_returns_none(self, mock_config: None, mock_default_file_limits: int) -> None:
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
+ def test_opening_statement_missing_returns_none(self) -> None:
# Arrange
features = {}
@@ -105,7 +106,8 @@ class TestGetParametersFromFeatureDict:
# Assert
assert result["opening_statement"] is None
- def test_all_features_provided(self, mock_config: None, mock_default_file_limits: int) -> None:
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
+ def test_all_features_provided(self) -> None:
# Arrange
features = {
"opening_statement": "Hi",
@@ -144,7 +146,8 @@ class TestGetParametersFromFeatureDict:
assert result_dict[key] == features[key]
assert result["user_input_form"] == user_input
- def test_file_upload_default_structure(self, mock_config: None, mock_default_file_limits: int) -> None:
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
+ def test_file_upload_default_structure(self) -> None:
# Arrange
features = {}
@@ -162,7 +165,8 @@ class TestGetParametersFromFeatureDict:
assert "remote_url" in file_upload["image"]["transfer_methods"]
assert "local_file" in file_upload["image"]["transfer_methods"]
- def test_system_parameters_from_config(self, mock_config: None, mock_default_file_limits: int) -> None:
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
+ def test_system_parameters_from_config(self) -> None:
# Arrange
features = {}
@@ -202,9 +206,8 @@ class TestGetParametersFromFeatureDict:
"user_input_form",
[None, "invalid", 123],
)
- def test_user_input_form_invalid_type(
- self, mock_config: None, mock_default_file_limits: int, user_input_form: object
- ) -> None:
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
+ def test_user_input_form_invalid_type(self, user_input_form: object) -> None:
# Arrange
features = {}
@@ -217,7 +220,8 @@ class TestGetParametersFromFeatureDict:
# Assert
assert result["user_input_form"] == user_input_form
- def test_empty_user_input_form(self, mock_config: None, mock_default_file_limits: int) -> None:
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
+ def test_empty_user_input_form(self) -> None:
features = {}
user_input = []
@@ -228,7 +232,8 @@ class TestGetParametersFromFeatureDict:
assert result["user_input_form"] == []
- def test_feature_values_none(self, mock_config: None, mock_default_file_limits: int) -> None:
+ @pytest.mark.usefixtures("mock_config", "mock_default_file_limits")
+ def test_feature_values_none(self) -> None:
features: dict[str, object] = {
"suggested_questions": None,
"speech_to_text": None,
diff --git a/api/tests/unit_tests/core/trigger/debug/test_debug_event_selectors.py b/api/tests/unit_tests/core/trigger/debug/test_debug_event_selectors.py
index 323e71f66ca..3fbe1993bd1 100644
--- a/api/tests/unit_tests/core/trigger/debug/test_debug_event_selectors.py
+++ b/api/tests/unit_tests/core/trigger/debug/test_debug_event_selectors.py
@@ -9,10 +9,11 @@ from __future__ import annotations
import json
from datetime import datetime
-from typing import Any
+from typing import cast
from unittest.mock import MagicMock, patch
import pytest
+from typing_extensions import TypedDict
from core.plugin.entities.request import TriggerInvokeEventResponse
from core.trigger.constants import (
@@ -28,6 +29,7 @@ from core.trigger.debug.event_selectors import (
select_trigger_debug_events,
)
from core.trigger.debug.events import PluginTriggerDebugEvent, WebhookDebugEvent
+from graphon.entities.graph_config import NodeConfigDict
from graphon.enums import BuiltinNodeTypes, NodeType, WorkflowType
from models.model import App, AppMode
from models.workflow import Workflow
@@ -35,17 +37,26 @@ from tests.unit_tests.core.trigger.conftest import VALID_PROVIDER_ID
from tests.unit_tests.model_factories import make_app
-def _make_poller_args(node_config: dict[str, Any] | None = None) -> dict[str, Any]:
+class _PollerArgs(TypedDict, closed=True):
+ tenant_id: str
+ user_id: str
+ app_id: str
+ node_config: NodeConfigDict
+ node_id: str
+
+
+def _make_poller_args(node_config: dict[str, object] | None = None) -> _PollerArgs:
return {
"tenant_id": "t1",
"user_id": "u1",
"app_id": "a1",
- "node_config": node_config or {"data": {}},
+ # The pollers only read node_config["data"]; the tests do not build a full graph node config.
+ "node_config": cast(NodeConfigDict, node_config or {"data": {}}),
"node_id": "n1",
}
-def _plugin_node_config(provider_id: str = VALID_PROVIDER_ID) -> dict[str, Any]:
+def _plugin_node_config(provider_id: str = VALID_PROVIDER_ID) -> dict[str, object]:
"""Valid node config for TriggerEventNodeData.model_validate."""
return {
"data": {
@@ -190,17 +201,6 @@ class TestWebhookTriggerDebugEventPoller:
class TestScheduleTriggerDebugEventPoller:
- def _make_schedule_poller(
- self, mock_redis: MagicMock, mock_schedule_svc: MagicMock, next_run_at: datetime
- ) -> ScheduleTriggerDebugEventPoller:
- """Set up mocks and create a schedule poller."""
- mock_redis.get.return_value = None
- mock_schedule_config = MagicMock()
- mock_schedule_config.cron_expression = "0 * * * *"
- mock_schedule_config.timezone = "UTC"
- mock_schedule_svc.to_schedule_config.return_value = mock_schedule_config
- return ScheduleTriggerDebugEventPoller(**_make_poller_args())
-
@patch("core.trigger.debug.event_selectors.redis_client")
@patch("core.trigger.debug.event_selectors.naive_utc_now")
@patch("core.trigger.debug.event_selectors.calculate_next_run_at")
diff --git a/api/tests/unit_tests/extensions/otel/decorators/test_base.py b/api/tests/unit_tests/extensions/otel/decorators/test_base.py
index 04a505febc2..c9f05eb1d10 100644
--- a/api/tests/unit_tests/extensions/otel/decorators/test_base.py
+++ b/api/tests/unit_tests/extensions/otel/decorators/test_base.py
@@ -11,7 +11,6 @@ Test coverage:
from collections.abc import Callable
import pytest
-from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.trace import StatusCode
@@ -26,7 +25,8 @@ def _otel_enabled(config_overrides: Callable[..., None]) -> None:
class TestTraceSpanDecorator:
"""Test trace_span decorator basic functionality."""
- def test_decorated_function_executes_normally(self, tracer_provider_with_memory_exporter: TracerProvider) -> None:
+ @pytest.mark.usefixtures("tracer_provider_with_memory_exporter")
+ def test_decorated_function_executes_normally(self) -> None:
"""Test that decorated function executes and returns correct value."""
@trace_span()
@@ -36,7 +36,8 @@ class TestTraceSpanDecorator:
result = test_func(2, 3)
assert result == 5
- def test_decorator_with_args_and_kwargs(self, tracer_provider_with_memory_exporter: TracerProvider) -> None:
+ @pytest.mark.usefixtures("tracer_provider_with_memory_exporter")
+ def test_decorator_with_args_and_kwargs(self) -> None:
"""Test that decorator correctly handles args and kwargs."""
@trace_span()
@@ -50,9 +51,8 @@ class TestTraceSpanDecorator:
class TestTraceSpanWithMemoryExporter:
"""Test trace_span with MemorySpanExporter to verify span creation."""
- def test_span_is_created_and_exported(
- self, tracer_provider_with_memory_exporter: TracerProvider, memory_span_exporter: InMemorySpanExporter
- ) -> None:
+ @pytest.mark.usefixtures("tracer_provider_with_memory_exporter")
+ def test_span_is_created_and_exported(self, memory_span_exporter: InMemorySpanExporter) -> None:
"""Test that span is created and exported to memory exporter."""
@trace_span()
@@ -64,9 +64,8 @@ class TestTraceSpanWithMemoryExporter:
spans = memory_span_exporter.get_finished_spans()
assert len(spans) == 1
- def test_span_name_matches_function(
- self, tracer_provider_with_memory_exporter: TracerProvider, memory_span_exporter: InMemorySpanExporter
- ) -> None:
+ @pytest.mark.usefixtures("tracer_provider_with_memory_exporter")
+ def test_span_name_matches_function(self, memory_span_exporter: InMemorySpanExporter) -> None:
"""Test that span name matches the decorated function."""
@trace_span()
@@ -79,9 +78,8 @@ class TestTraceSpanWithMemoryExporter:
assert len(spans) == 1
assert "my_test_function" in spans[0].name
- def test_span_status_is_ok_on_success(
- self, tracer_provider_with_memory_exporter: TracerProvider, memory_span_exporter: InMemorySpanExporter
- ) -> None:
+ @pytest.mark.usefixtures("tracer_provider_with_memory_exporter")
+ def test_span_status_is_ok_on_success(self, memory_span_exporter: InMemorySpanExporter) -> None:
"""Test that span status is OK when function succeeds."""
@trace_span()
@@ -94,9 +92,8 @@ class TestTraceSpanWithMemoryExporter:
assert len(spans) == 1
assert spans[0].status.status_code == StatusCode.OK
- def test_span_status_is_error_on_exception(
- self, tracer_provider_with_memory_exporter: TracerProvider, memory_span_exporter: InMemorySpanExporter
- ) -> None:
+ @pytest.mark.usefixtures("tracer_provider_with_memory_exporter")
+ def test_span_status_is_error_on_exception(self, memory_span_exporter: InMemorySpanExporter) -> None:
"""Test that span status is ERROR when function raises exception."""
@trace_span()
@@ -110,9 +107,8 @@ class TestTraceSpanWithMemoryExporter:
assert len(spans) == 1
assert spans[0].status.status_code == StatusCode.ERROR
- def test_exception_is_recorded_in_span(
- self, tracer_provider_with_memory_exporter: TracerProvider, memory_span_exporter: InMemorySpanExporter
- ) -> None:
+ @pytest.mark.usefixtures("tracer_provider_with_memory_exporter")
+ def test_exception_is_recorded_in_span(self, memory_span_exporter: InMemorySpanExporter) -> None:
"""Test that exception details are recorded in span events."""
@trace_span()
diff --git a/api/tests/unit_tests/extensions/otel/decorators/test_handler.py b/api/tests/unit_tests/extensions/otel/decorators/test_handler.py
index c2b80497e81..688b6d1f335 100644
--- a/api/tests/unit_tests/extensions/otel/decorators/test_handler.py
+++ b/api/tests/unit_tests/extensions/otel/decorators/test_handler.py
@@ -227,9 +227,7 @@ class TestSpanHandlerWrapper:
with pytest.raises(ValueError, match="test error"):
handler.wrapper(tracer, test_func)
- def test_wrapper_passes_arguments_correctly(
- self, tracer_provider_with_memory_exporter: TracerProvider, memory_span_exporter: InMemorySpanExporter
- ) -> None:
+ def test_wrapper_passes_arguments_correctly(self, tracer_provider_with_memory_exporter: TracerProvider) -> None:
"""Test that wrapper correctly passes arguments to wrapped function."""
handler = SpanHandler()
tracer = tracer_provider_with_memory_exporter.get_tracer(__name__)
diff --git a/api/tests/unit_tests/services/test_archive_workflow_run_logs.py b/api/tests/unit_tests/services/test_archive_workflow_run_logs.py
index ab6c23e16c3..0c06aff568c 100644
--- a/api/tests/unit_tests/services/test_archive_workflow_run_logs.py
+++ b/api/tests/unit_tests/services/test_archive_workflow_run_logs.py
@@ -8,7 +8,7 @@ This module contains tests for:
from collections.abc import Callable
from datetime import datetime
-from unittest.mock import MagicMock, patch
+from unittest.mock import MagicMock
from enums import DeploymentEdition
@@ -16,8 +16,7 @@ from enums import DeploymentEdition
class TestWorkflowRunArchiver:
"""Tests for the WorkflowRunArchiver class."""
- @patch("services.retention.workflow_run.archive_paid_plan_workflow_run.get_archive_storage", autospec=True)
- def test_archiver_initialization(self, mock_get_storage: MagicMock, config_overrides: Callable[..., None]) -> None:
+ def test_archiver_initialization(self, config_overrides: Callable[..., None]) -> None:
"""Test archiver can be initialized with various options."""
from services.retention.workflow_run.archive_paid_plan_workflow_run import WorkflowRunArchiver
diff --git a/api/tests/unit_tests/services/test_dataset_service_lock_not_owned.py b/api/tests/unit_tests/services/test_dataset_service_lock_not_owned.py
index 0b0f8355051..a143ee76e81 100644
--- a/api/tests/unit_tests/services/test_dataset_service_lock_not_owned.py
+++ b/api/tests/unit_tests/services/test_dataset_service_lock_not_owned.py
@@ -52,7 +52,7 @@ def fake_features(monkeypatch: pytest.MonkeyPatch) -> types.SimpleNamespace:
)
monkeypatch.setattr(
"services.knowledge.dataset_service.FeatureService.get_features",
- lambda tenant_id, **_kwargs: features,
+ lambda _tenant_id, **_kwargs: features,
)
return features
@@ -61,7 +61,7 @@ def fake_features(monkeypatch: pytest.MonkeyPatch) -> types.SimpleNamespace:
def fake_lock(monkeypatch: pytest.MonkeyPatch) -> None:
"""Patch redis_client.lock to always raise LockNotOwnedError on enter."""
- def _fake_lock(name: str, timeout: float | None = None, *args: object, **kwargs: object) -> FakeLock:
+ def _fake_lock(*_args: object, **_kwargs: object) -> FakeLock:
return FakeLock()
# DatasetService imports redis_client directly from extensions.ext_redis
@@ -74,11 +74,10 @@ def fake_lock(monkeypatch: pytest.MonkeyPatch) -> None:
@pytest.mark.parametrize("sqlite_session", [(Account, Tenant, Dataset, DatasetProcessRule, Document)], indirect=True)
[email protected]("fake_features", "fake_lock")
def test_save_document_with_dataset_id_ignores_lock_not_owned(
monkeypatch: pytest.MonkeyPatch,
fake_current_user: Account,
- fake_features: types.SimpleNamespace,
- fake_lock: None,
sqlite_session: Session,
) -> None:
# Arrange
@@ -112,7 +111,9 @@ def test_save_document_with_dataset_id_ignores_lock_not_owned(
account = fake_current_user
# Avoid touching real doc_form logic
- monkeypatch.setattr("services.knowledge.dataset_service.DatasetService.check_doc_form", lambda *a, **k: None)
+ monkeypatch.setattr(
+ "services.knowledge.dataset_service.DatasetService.check_doc_form", lambda *_args, **_kwargs: None
+ )
# Act: this would hit the redis lock, whose __enter__ raises LockNotOwnedError.
# Our implementation should catch it and still return (documents, batch).
@@ -146,10 +147,9 @@ def test_save_document_with_dataset_id_ignores_lock_not_owned(
@pytest.mark.parametrize("sqlite_session", [(Account, Tenant, Dataset, Document, DocumentSegment)], indirect=True)
[email protected]("fake_lock")
def test_multi_create_segment_ignores_lock_not_owned(
- monkeypatch: pytest.MonkeyPatch,
fake_current_user: Account,
- fake_lock: None,
sqlite_session: Session,
) -> None:
# Arrange
diff --git a/api/tests/unit_tests/services/test_feature_service_human_input_email_delivery.py b/api/tests/unit_tests/services/test_feature_service_human_input_email_delivery.py
index 26e58b67f65..6bc9cdb108a 100644
--- a/api/tests/unit_tests/services/test_feature_service_human_input_email_delivery.py
+++ b/api/tests/unit_tests/services/test_feature_service_human_input_email_delivery.py
@@ -88,7 +88,7 @@ def test_get_vector_space_converts_billing_float_size(
monkeypatch.setattr(
feature_service_module.BillingService,
"get_vector_space",
- lambda tenant_id: {"size": 5120.75, "limit": 20480},
+ lambda _tenant_id: {"size": 5120.75, "limit": 20480},
)
result = FeatureService.get_vector_space("tenant-1")
@@ -105,7 +105,7 @@ def test_get_vector_space_preserves_unknown_usage(
monkeypatch.setattr(
feature_service_module.BillingService,
"get_vector_space",
- lambda tenant_id: {"size": 0.0, "limit": 50, "usage_unknown": True},
+ lambda _tenant_id: {"size": 0.0, "limit": 50, "usage_unknown": True},
)
result = FeatureService.get_vector_space("tenant-1")
diff --git a/api/tests/unit_tests/services/test_model_load_balancing_service.py b/api/tests/unit_tests/services/test_model_load_balancing_service.py
index 98ffa1d3564..c4261dd5f0a 100644
--- a/api/tests/unit_tests/services/test_model_load_balancing_service.py
+++ b/api/tests/unit_tests/services/test_model_load_balancing_service.py
@@ -96,7 +96,7 @@ def service(monkeypatch: pytest.MonkeyPatch, sqlite_session: Session) -> Service
svc = ModelLoadBalancingService()
monkeypatch.setattr(svc, "_get_provider_manager", lambda _tenant_id: manager)
monkeypatch.setattr(
- "services.model_load_balancing_service.create_plugin_provider_manager", lambda tenant_id: manager
+ "services.model_load_balancing_service.create_plugin_provider_manager", lambda **_kwargs: manager
)
monkeypatch.setattr(
"services.model_load_balancing_service.ProviderManager.invalidate_configurations_cache", MagicMock()
diff --git a/api/tests/unit_tests/services/test_model_provider_service_sanitization.py b/api/tests/unit_tests/services/test_model_provider_service_sanitization.py
index 392f068e86b..f0474364faa 100644
--- a/api/tests/unit_tests/services/test_model_provider_service_sanitization.py
+++ b/api/tests/unit_tests/services/test_model_provider_service_sanitization.py
@@ -67,7 +67,7 @@ def service_with_fake_configurations(monkeypatch: pytest.MonkeyPatch) -> ModelPr
)
class _FakeProviderManager:
- def get_configurations(self, tenant_id: str) -> _FakeConfigurations:
+ def get_configurations(self, _tenant_id: str) -> _FakeConfigurations:
return _FakeConfigurations(fake_provider_configuration)
svc = ModelProviderService()