From b9022d930c1d656f5319a877ebb17b1007bc3ef8 Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Sun, 10 May 2026 18:59:13 -0700 Subject: [PATCH] fix: Make failing tests environment aware --- .../custom/component/test_dynamic_imports.py | 18 +++++++++++++----- src/lfx/tests/unit/test_flow_requirements.py | 12 +++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/lfx/tests/unit/custom/component/test_dynamic_imports.py b/src/lfx/tests/unit/custom/component/test_dynamic_imports.py index 35f461e990..64699e171b 100644 --- a/src/lfx/tests/unit/custom/component/test_dynamic_imports.py +++ b/src/lfx/tests/unit/custom/component/test_dynamic_imports.py @@ -209,17 +209,25 @@ class TestComponentDynamicImports: """Test that TYPE_CHECKING imports work correctly with dynamic loading.""" # This test ensures that imports in TYPE_CHECKING blocks # work correctly with the dynamic import system + import importlib.util + import lfx.components.searchapi as searchapi_components # Components should be available for dynamic loading assert "SearchComponent" in searchapi_components.__all__ assert "SearchComponent" in searchapi_components._dynamic_imports - # langchain-community is now transitively provided by lfx (via OpenDsStar), - # so accessing SearchComponent triggers a successful dynamic import. - component = searchapi_components.SearchComponent - assert component is not None - assert hasattr(component, "__init__") + # SearchComponent imports from langchain_community at module-import time. + # If that package is present in this environment (e.g. transitively via + # OpenDsStar), the dynamic import should succeed; otherwise it should + # raise AttributeError wrapping the ImportError. + if importlib.util.find_spec("langchain_community") is not None: + component = searchapi_components.SearchComponent + assert component is not None + assert hasattr(component, "__init__") + else: + with pytest.raises(AttributeError, match=r"Could not import.*SearchComponent"): + _ = searchapi_components.SearchComponent class TestPerformanceCharacteristics: diff --git a/src/lfx/tests/unit/test_flow_requirements.py b/src/lfx/tests/unit/test_flow_requirements.py index b304fad331..6674c80892 100644 --- a/src/lfx/tests/unit/test_flow_requirements.py +++ b/src/lfx/tests/unit/test_flow_requirements.py @@ -719,12 +719,18 @@ class TestStarterProjects: def test_simple_agent_has_community(self, simple_agent_flow): """Simple Agent's URLComponent imports langchain_community. - lfx now provides langchain-community transitively (via OpenDsStar), - so it is filtered out of generated requirements as already-provided. + When lfx provides langchain-community transitively (e.g. via + OpenDsStar in some environments) it is filtered out of generated + requirements as already-provided; otherwise it should appear. """ + from lfx.utils.flow_requirements import _get_lfx_provided_imports + result = generate_requirements_from_flow(simple_agent_flow, pin_versions=False) assert "lfx" in result - assert "langchain-community" not in result + if "langchain_community" in _get_lfx_provided_imports(): + assert "langchain-community" not in result + else: + assert "langchain-community" in result def test_basic_prompting_from_file(self): """Test the file-based API.