The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
core[patch]: Speed up unit tests for imports (#23837)
Eugene Yurtsev4ab78572e73a
diff --git a/libs/core/tests/unit_tests/test_imports.py b/libs/core/tests/unit_tests/test_imports.pyindex 7d64113378..887811b5bd 100644--- a/libs/core/tests/unit_tests/test_imports.py+++ b/libs/core/tests/unit_tests/test_imports.py@@ -1,9 +1,9 @@+import concurrent.futuresimport globimport importlibimport subprocessfrom pathlib import Path--import pytest+from typing import Tupledef test_importable_all() -> None:@@ -17,11 +17,40 @@ def test_importable_all() -> None:for cls_ in all_:getattr(module, cls_)- # Test import in isolation- # Note: ImportErrors due to circular imports can be raised- # for one sequence of imports but not another.- result = subprocess.run(- ["python", "-c", f"import langchain_core.{module_name}"],- )- if result.returncode != 0:- pytest.fail(f"Failed to import {module_name}.")++def try_to_import(module_name: str) -> Tuple[int, str]:+ """Try to import a module via subprocess."""+ module = importlib.import_module("langchain_core." + module_name)+ all_ = getattr(module, "__all__", [])+ for cls_ in all_:+ getattr(module, cls_)++ result = subprocess.run(+ ["python", "-c", f"import langchain_core.{module_name}"],+ )+ return result.returncode, module_name+++def test_importable_all_via_subprocess() -> None:+ """Test import in isolation.++ Note: ImportErrors due to circular imports can be raised+ for one sequence of imports but not another.+ """+ module_names = []+ for path in glob.glob("../core/langchain_core/*"):+ relative_path = Path(path).parts[-1]+ if relative_path.endswith(".typed"):+ continue+ module_name = relative_path.split(".")[0]+ module_names.append(module_name)++ with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:+ futures = [+ executor.submit(try_to_import, module_name) for module_name in module_names+ ]+ for future in concurrent.futures.as_completed(futures):+ result = future.result() # Will raise an exception if the callable raised+ code, module_name = result+ if code != 0:+ raise ValueError(f"Failed to import {module_name}.")