kaxil commented on code in PR #67237: URL: https://github.com/apache/airflow/pull/67237#discussion_r3274538738
########## providers/common/ai/tests/unit/common/ai/hooks/test_langchain.py: ########## @@ -16,13 +16,36 @@ # under the License. from __future__ import annotations +import sys from unittest.mock import MagicMock, patch import pytest from airflow.providers.common.ai.hooks.langchain import LangChainHook [email protected](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 Review Comment: Do you know why was this NOT installed: https://github.com/apache/airflow/pull/67192 should have it installed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
