The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
refactor(standard-tests): improve VCR config (#33968)
Christophe Bornetf5b6eecf7226
diff --git a/libs/langchain_v1/tests/unit_tests/conftest.py b/libs/langchain_v1/tests/unit_tests/conftest.pyindex e846f9432f..ebc0b8376e 100644--- a/libs/langchain_v1/tests/unit_tests/conftest.py+++ b/libs/langchain_v1/tests/unit_tests/conftest.py@@ -5,10 +5,7 @@ from importlib import utilfrom typing import Anyimport pytest-from langchain_tests.conftest import CustomPersister, CustomSerializer-from langchain_tests.conftest import (- _base_vcr_config as _base_vcr_config, # noqa: PLC0414-)+from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_configfrom vcr import VCR_EXTRA_HEADERS = [@@ -34,9 +31,9 @@ def remove_response_headers(response: dict) -> dict:@pytest.fixture(scope="session")-def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811+def vcr_config() -> dict:"""Extend the default configuration coming from langchain_tests."""- config = _base_vcr_config.copy()+ config = base_vcr_config()config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)config["before_record_request"] = remove_request_headersconfig["before_record_response"] = remove_response_headersdiff --git a/libs/partners/anthropic/tests/conftest.py b/libs/partners/anthropic/tests/conftest.pyindex ba705a7d5d..fb1a34ae8a 100644--- a/libs/partners/anthropic/tests/conftest.py+++ b/libs/partners/anthropic/tests/conftest.py@@ -1,10 +1,7 @@from typing import Anyimport pytest-from langchain_tests.conftest import CustomPersister, CustomSerializer-from langchain_tests.conftest import (- _base_vcr_config as _base_vcr_config, # noqa: PLC0414-)+from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_configfrom vcr import VCR # type: ignore[import-untyped]@@ -21,9 +18,9 @@ def remove_response_headers(response: dict) -> dict:@pytest.fixture(scope="session")-def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811+def vcr_config() -> dict:"""Extend the default configuration coming from langchain_tests."""- config = _base_vcr_config.copy()+ config = base_vcr_config()config["before_record_request"] = remove_request_headersconfig["before_record_response"] = remove_response_headersconfig["serializer"] = "yaml.gz"diff --git a/libs/partners/groq/tests/conftest.py b/libs/partners/groq/tests/conftest.pyindex ba705a7d5d..fb1a34ae8a 100644--- a/libs/partners/groq/tests/conftest.py+++ b/libs/partners/groq/tests/conftest.py@@ -1,10 +1,7 @@from typing import Anyimport pytest-from langchain_tests.conftest import CustomPersister, CustomSerializer-from langchain_tests.conftest import (- _base_vcr_config as _base_vcr_config, # noqa: PLC0414-)+from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_configfrom vcr import VCR # type: ignore[import-untyped]@@ -21,9 +18,9 @@ def remove_response_headers(response: dict) -> dict:@pytest.fixture(scope="session")-def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811+def vcr_config() -> dict:"""Extend the default configuration coming from langchain_tests."""- config = _base_vcr_config.copy()+ config = base_vcr_config()config["before_record_request"] = remove_request_headersconfig["before_record_response"] = remove_response_headersconfig["serializer"] = "yaml.gz"diff --git a/libs/partners/openai/tests/conftest.py b/libs/partners/openai/tests/conftest.pyindex 77c231f915..af85f90c10 100644--- a/libs/partners/openai/tests/conftest.py+++ b/libs/partners/openai/tests/conftest.py@@ -1,10 +1,7 @@from typing import Anyimport pytest-from langchain_tests.conftest import CustomPersister, CustomSerializer-from langchain_tests.conftest import (- _base_vcr_config as _base_vcr_config, # noqa: PLC0414-)+from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_configfrom vcr import VCR # type: ignore[import-untyped]_EXTRA_HEADERS = [@@ -30,9 +27,9 @@ def remove_response_headers(response: dict) -> dict:@pytest.fixture(scope="session")-def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811+def vcr_config() -> dict:"""Extend the default configuration coming from langchain_tests."""- config = _base_vcr_config.copy()+ config = base_vcr_config()config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)config["before_record_request"] = remove_request_headersconfig["before_record_response"] = remove_response_headersdiff --git a/libs/standard-tests/langchain_tests/conftest.py b/libs/standard-tests/langchain_tests/conftest.pyindex 161fc744cb..bfee299005 100644--- a/libs/standard-tests/langchain_tests/conftest.py+++ b/libs/standard-tests/langchain_tests/conftest.py@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Any, castimport pytestimport yaml+from langchain_core._api.deprecation import deprecatedfrom vcr import VCRfrom vcr.persisters.filesystem import CassetteNotFoundErrorfrom vcr.request import Request@@ -98,8 +99,7 @@ _BASE_FILTER_HEADERS = [][email protected](scope="session")-def _base_vcr_config() -> dict:+def base_vcr_config() -> dict:"""Return VCR configuration that every cassette will receive.(Anything permitted by `vcr.VCR(**kwargs)` can be put here.)@@ -116,6 +116,12 @@ def _base_vcr_config() -> dict:@pytest.fixture(scope="session")-def vcr_config(_base_vcr_config: dict) -> dict:+@deprecated("1.0.3", alternative="base_vcr_config", removal="2.0")+def _base_vcr_config() -> dict:+ return base_vcr_config()++[email protected](scope="session")+def vcr_config() -> dict:"""VCR config fixture."""- return _base_vcr_config+ return base_vcr_config()diff --git a/libs/standard-tests/langchain_tests/integration_tests/chat_models.py b/libs/standard-tests/langchain_tests/integration_tests/chat_models.pyindex f547ef3711..06d42ef6b0 100644--- a/libs/standard-tests/langchain_tests/integration_tests/chat_models.py+++ b/libs/standard-tests/langchain_tests/integration_tests/chat_models.py@@ -628,9 +628,7 @@ class ChatModelIntegrationTests(ChatModelTests):```python title="tests/conftest.py"import pytest- from langchain_tests.conftest import (- _base_vcr_config as _base_vcr_config,- )+ from langchain_tests.conftest import base_vcr_config_EXTRA_HEADERS = [# Specify additional headers to redact@@ -645,9 +643,9 @@ class ChatModelIntegrationTests(ChatModelTests):@pytest.fixture(scope="session")- def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811+ def vcr_config() -> dict:"""Extend the default configuration from langchain_tests."""- config = _base_vcr_config.copy()+ config = base_vcr_config()config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)config["before_record_response"] = remove_response_headers@@ -667,9 +665,7 @@ class ChatModelIntegrationTests(ChatModelTests):CustomPersister,CustomSerializer,)- from langchain_tests.conftest import (- _base_vcr_config as _base_vcr_config,- )+ from langchain_tests.conftest import base_vcr_configfrom vcr import VCR_EXTRA_HEADERS = [@@ -685,9 +681,9 @@ class ChatModelIntegrationTests(ChatModelTests):@pytest.fixture(scope="session")- def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811+ def vcr_config() -> dict:"""Extend the default configuration from langchain_tests."""- config = _base_vcr_config.copy()+ config = base_vcr_config()config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)config["before_record_response"] = remove_response_headers# New: enable serializer and set file extensiondiff --git a/libs/standard-tests/langchain_tests/unit_tests/chat_models.py b/libs/standard-tests/langchain_tests/unit_tests/chat_models.pyindex 5460623bd9..bfec8d53a1 100644--- a/libs/standard-tests/langchain_tests/unit_tests/chat_models.py+++ b/libs/standard-tests/langchain_tests/unit_tests/chat_models.py@@ -759,9 +759,7 @@ class ChatModelUnitTests(ChatModelTests):```python title="tests/conftest.py"import pytest- from langchain_tests.conftest import (- _base_vcr_config as _base_vcr_config,- )+ from langchain_tests.conftest import base_vcr_config_EXTRA_HEADERS = [# Specify additional headers to redact@@ -776,9 +774,9 @@ class ChatModelUnitTests(ChatModelTests):@pytest.fixture(scope="session")- def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811+ def vcr_config() -> dict:"""Extend the default configuration from langchain_tests."""- config = _base_vcr_config.copy()+ config = base_vcr_config()config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)config["before_record_response"] = remove_response_headers@@ -798,9 +796,7 @@ class ChatModelUnitTests(ChatModelTests):CustomPersister,CustomSerializer,)- from langchain_tests.conftest import (- _base_vcr_config as _base_vcr_config,- )+ from langchain_tests.conftest import base_vcr_configfrom vcr import VCR_EXTRA_HEADERS = [@@ -816,9 +812,9 @@ class ChatModelUnitTests(ChatModelTests):@pytest.fixture(scope="session")- def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811+ def vcr_config() -> dict:"""Extend the default configuration from langchain_tests."""- config = _base_vcr_config.copy()+ config = base_vcr_config()config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)config["before_record_response"] = remove_response_headers# New: enable serializer and set file extension