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.

test: replace logger mock with caplog in workflow collaboration test (#37971)

ojasarora.ethbb921bcc4584
diff --git a/api/tests/unit_tests/services/test_workflow_collaboration_service.py b/api/tests/unit_tests/services/test_workflow_collaboration_service.py
index 8a6addfeced..93d9b576f97 100644
--- a/api/tests/unit_tests/services/test_workflow_collaboration_service.py
+++ b/api/tests/unit_tests/services/test_workflow_collaboration_service.py
@@ -1,3 +1,4 @@
+import logging
from unittest.mock import Mock, patch
import pytest
@@ -427,16 +428,20 @@ class TestWorkflowCollaborationService:
repository.delete_leader.assert_not_called()
def test_broadcast_leader_change_logs_emit_errors(
- self, service: tuple[WorkflowCollaborationService, Mock, Mock]
+ self,
+ service: tuple[WorkflowCollaborationService, Mock, Mock],
+ caplog: pytest.LogCaptureFixture,
) -> None:
collaboration_service, repository, socketio = service
repository.get_session_sids.return_value = ["sid-1", "sid-2"]
socketio.emit.side_effect = [RuntimeError("boom"), None]
- with patch("services.workflow_collaboration_service.logging.exception") as exception_mock:
+ with caplog.at_level(logging.ERROR):
collaboration_service.broadcast_leader_change("wf-1", "sid-2")
- assert exception_mock.call_count == 1
+ error_records = [record for record in caplog.records if record.levelno == logging.ERROR]
+ assert len(error_records) == 1
+ assert "Failed to emit leader status to session sid-1" in caplog.text
def test_broadcast_online_users_sorts_and_emits(
self, service: tuple[WorkflowCollaborationService, Mock, Mock]