Re: [PR] Fix LangChain hook tests failing when langchain is not installed [airflow]
kaxil merged PR #67237: URL: https://github.com/apache/airflow/pull/67237 -- 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]
Re: [PR] Fix LangChain hook tests failing when langchain is not installed [airflow]
amoghrajesh commented on code in PR #67237: URL: https://github.com/apache/airflow/pull/67237#discussion_r3274890988 ## 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: Yes, so `langchain` is in the dev dependency group in pyproject.toml from https://github.com/apache/airflow/pull/67192, which is only synced during local development (uv sync). CI installs providers using `uv sync --all-packages` which picks up dependencies and optional dependencies extras. So `langchain` is absent from the CI test environment. The non-DB providers job is the only one that ran these tests — the DB jobs in that run skipped them because the langchain tests have no `@pytest.mark.db_test`. -- 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]
Re: [PR] Fix LangChain hook tests failing when langchain is not installed [airflow]
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]
