Skip to content

Commit e97baeb

Browse files
authored
test(core): suppress pydantic_v1 deprecation warnings during import tests (#33106)
We intentionally import these. Hide warnings to reduce testing noise.
1 parent 3a6046b commit e97baeb

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

libs/core/tests/unit_tests/test_imports.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
11
import concurrent.futures
22
import importlib
33
import subprocess
4+
import warnings
45
from pathlib import Path
56

67

78
def test_importable_all() -> None:
8-
for path in Path("../core/langchain_core/").glob("*"):
9-
module_name = path.stem
10-
if not module_name.startswith(".") and path.suffix != ".typed":
11-
module = importlib.import_module("langchain_core." + module_name)
12-
all_ = getattr(module, "__all__", [])
13-
for cls_ in all_:
14-
getattr(module, cls_)
9+
with warnings.catch_warnings():
10+
# Suppress pydantic_v1 deprecation warnings during import testing
11+
# These warnings are expected as modules transition from pydantic v1 to v2
12+
# and are not relevant to testing importability
13+
warnings.filterwarnings(
14+
"ignore",
15+
message=".*langchain_core.pydantic_v1.*",
16+
category=DeprecationWarning,
17+
)
18+
for path in Path("../core/langchain_core/").glob("*"):
19+
module_name = path.stem
20+
if not module_name.startswith(".") and path.suffix != ".typed":
21+
module = importlib.import_module("langchain_core." + module_name)
22+
all_ = getattr(module, "__all__", [])
23+
for cls_ in all_:
24+
getattr(module, cls_)
1525

1626

1727
def try_to_import(module_name: str) -> tuple[int, str]:
1828
"""Try to import a module via subprocess."""
19-
module = importlib.import_module("langchain_core." + module_name)
20-
all_ = getattr(module, "__all__", [])
21-
for cls_ in all_:
22-
getattr(module, cls_)
29+
with warnings.catch_warnings():
30+
# Suppress pydantic_v1 deprecation warnings during import testing
31+
# These warnings are expected as modules transition from pydantic v1 to v2
32+
# and are not relevant to testing importability
33+
warnings.filterwarnings(
34+
"ignore",
35+
message=".*langchain_core.pydantic_v1.*",
36+
category=DeprecationWarning,
37+
)
38+
module = importlib.import_module("langchain_core." + module_name)
39+
all_ = getattr(module, "__all__", [])
40+
for cls_ in all_:
41+
getattr(module, cls_)
2342

2443
result = subprocess.run(
2544
["python", "-c", f"import langchain_core.{module_name}"], check=True
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import importlib
2+
import warnings
23
from pathlib import Path
34

45
from pydantic import BaseModel
56

67

78
def test_all_models_built() -> None:
8-
for path in Path("../core/langchain_core/").glob("*"):
9-
module_name = path.stem
10-
if not module_name.startswith(".") and path.suffix != ".typed":
11-
module = importlib.import_module("langchain_core." + module_name)
12-
all_ = getattr(module, "__all__", [])
13-
for attr_name in all_:
14-
attr = getattr(module, attr_name)
15-
try:
16-
if issubclass(attr, BaseModel):
17-
assert attr.__pydantic_complete__ is True
18-
except TypeError:
19-
# This is expected for non-class attributes
20-
pass
9+
with warnings.catch_warnings():
10+
# Suppress pydantic_v1 deprecation warnings during import testing
11+
# These warnings are expected as modules transition from pydantic v1 to v2
12+
# and are not relevant to testing pydantic model completeness
13+
warnings.filterwarnings(
14+
"ignore",
15+
message=".*langchain_core.pydantic_v1.*",
16+
category=DeprecationWarning,
17+
)
18+
for path in Path("../core/langchain_core/").glob("*"):
19+
module_name = path.stem
20+
if not module_name.startswith(".") and path.suffix != ".typed":
21+
module = importlib.import_module("langchain_core." + module_name)
22+
all_ = getattr(module, "__all__", [])
23+
for attr_name in all_:
24+
attr = getattr(module, attr_name)
25+
try:
26+
if issubclass(attr, BaseModel):
27+
assert attr.__pydantic_complete__ is True
28+
except TypeError:
29+
# This is expected for non-class attributes
30+
pass

0 commit comments

Comments
 (0)