fix: Make failing tests environment aware

This commit is contained in:
Eric Hare
2026-05-10 18:59:13 -07:00
parent c155a44010
commit b9022d930c
2 changed files with 22 additions and 8 deletions

View File

@ -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:

View File

@ -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.