You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2026/05/20 15:50:45 UTC
(airflow) branch main updated: Fix LangChain hook tests failing when langchain is not installed (#67237)
This is an automated email from the ASF dual-hosted git repository.
kaxil pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new fe1618f9f32 Fix LangChain hook tests failing when langchain is not installed (#67237)
fe1618f9f32 is described below
commit fe1618f9f328d62480e105b10a8b5d6a38c77fe7
Author: Amogh Desai <am...@gmail.com>
AuthorDate: Wed May 20 21:20:35 2026 +0530
Fix LangChain hook tests failing when langchain is not installed (#67237)
* Fix LangChain hook tests failing when langchain is not installed
* Fix LangChain hook tests failing when langchain is not installed
---
.../tests/unit/common/ai/hooks/test_langchain.py | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/providers/common/ai/tests/unit/common/ai/hooks/test_langchain.py b/providers/common/ai/tests/unit/common/ai/hooks/test_langchain.py
index ed2f9581937..646f72aa107 100644
--- a/providers/common/ai/tests/unit/common/ai/hooks/test_langchain.py
+++ b/providers/common/ai/tests/unit/common/ai/hooks/test_langchain.py
@@ -16,6 +16,7 @@
# under the License.
from __future__ import annotations
+import sys
from unittest.mock import MagicMock, patch
import pytest
@@ -23,6 +24,28 @@ import pytest
from airflow.providers.common.ai.hooks.langchain import LangChainHook
+@pytest.fixture(autouse=True)
+def _stub_langchain_modules():
+ # langchain is an optional dep; stub sys.modules so @patch can resolve
+ # langchain.* targets without it being installed.
+ # Submodule entries are derived from parent mock attributes so @patch
+ # (which resolves via getattr) and the hook's lazy imports (which read
+ # sys.modules["langchain.chat_models"]) see the same object.
+ lc = MagicMock()
+ lc_core = MagicMock()
+ mocks = {
+ "langchain": lc,
+ "langchain.chat_models": lc.chat_models,
+ "langchain.embeddings": lc.embeddings,
+ "langchain_core": lc_core,
+ "langchain_core.embeddings": lc_core.embeddings,
+ "langchain_core.language_models": lc_core.language_models,
+ "langchain_core.language_models.chat_models": lc_core.language_models.chat_models,
+ }
+ with patch.dict(sys.modules, mocks):
+ yield
+
+
def _conn(password: str = "", host: str = "", extra: dict | None = None) -> MagicMock:
mock_conn = MagicMock()
mock_conn.password = password