Skip to content

Commit a7beec4

Browse files
committed
refactor(standard-tests): improve VCR config
1 parent 275dcbf commit a7beec4

File tree

7 files changed

+34
-48
lines changed

7 files changed

+34
-48
lines changed

libs/langchain_v1/tests/unit_tests/conftest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
from typing import Any
66

77
import pytest
8-
from langchain_tests.conftest import CustomPersister, CustomSerializer
9-
from langchain_tests.conftest import (
10-
_base_vcr_config as _base_vcr_config,
11-
)
8+
from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_config
129
from vcr import VCR
1310

1411
_EXTRA_HEADERS = [
@@ -34,9 +31,9 @@ def remove_response_headers(response: dict) -> dict:
3431

3532

3633
@pytest.fixture(scope="session")
37-
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
34+
def vcr_config() -> dict:
3835
"""Extend the default configuration coming from langchain_tests."""
39-
config = _base_vcr_config.copy()
36+
config = base_vcr_config()
4037
config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)
4138
config["before_record_request"] = remove_request_headers
4239
config["before_record_response"] = remove_response_headers

libs/partners/anthropic/tests/conftest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from typing import Any
22

33
import pytest
4-
from langchain_tests.conftest import CustomPersister, CustomSerializer
5-
from langchain_tests.conftest import (
6-
_base_vcr_config as _base_vcr_config, # noqa: PLC0414
7-
)
4+
from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_config
85
from vcr import VCR # type: ignore[import-untyped]
96

107

@@ -21,9 +18,9 @@ def remove_response_headers(response: dict) -> dict:
2118

2219

2320
@pytest.fixture(scope="session")
24-
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
21+
def vcr_config() -> dict:
2522
"""Extend the default configuration coming from langchain_tests."""
26-
config = _base_vcr_config.copy()
23+
config = base_vcr_config()
2724
config["before_record_request"] = remove_request_headers
2825
config["before_record_response"] = remove_response_headers
2926
config["serializer"] = "yaml.gz"

libs/partners/groq/tests/conftest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from typing import Any
22

33
import pytest
4-
from langchain_tests.conftest import CustomPersister, CustomSerializer
5-
from langchain_tests.conftest import (
6-
_base_vcr_config as _base_vcr_config, # noqa: PLC0414
7-
)
4+
from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_config
85
from vcr import VCR # type: ignore[import-untyped]
96

107

@@ -21,9 +18,9 @@ def remove_response_headers(response: dict) -> dict:
2118

2219

2320
@pytest.fixture(scope="session")
24-
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
21+
def vcr_config() -> dict:
2522
"""Extend the default configuration coming from langchain_tests."""
26-
config = _base_vcr_config.copy()
23+
config = base_vcr_config()
2724
config["before_record_request"] = remove_request_headers
2825
config["before_record_response"] = remove_response_headers
2926
config["serializer"] = "yaml.gz"

libs/partners/openai/tests/conftest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from typing import Any
22

33
import pytest
4-
from langchain_tests.conftest import CustomPersister, CustomSerializer
5-
from langchain_tests.conftest import (
6-
_base_vcr_config as _base_vcr_config, # noqa: PLC0414
7-
)
4+
from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_config
85
from vcr import VCR # type: ignore[import-untyped]
96

107
_EXTRA_HEADERS = [
@@ -30,9 +27,9 @@ def remove_response_headers(response: dict) -> dict:
3027

3128

3229
@pytest.fixture(scope="session")
33-
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
30+
def vcr_config() -> dict:
3431
"""Extend the default configuration coming from langchain_tests."""
35-
config = _base_vcr_config.copy()
32+
config = base_vcr_config()
3633
config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)
3734
config["before_record_request"] = remove_request_headers
3835
config["before_record_response"] = remove_response_headers

libs/standard-tests/langchain_tests/conftest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010
import yaml
11+
from langchain_core._api.deprecation import deprecated
1112
from vcr import VCR
1213
from vcr.persisters.filesystem import CassetteNotFoundError
1314
from vcr.request import Request
@@ -98,8 +99,7 @@ def save_cassette(
9899
]
99100

100101

101-
@pytest.fixture(scope="session")
102-
def _base_vcr_config() -> dict:
102+
def base_vcr_config() -> dict:
103103
"""Return VCR configuration that every cassette will receive.
104104
105105
(Anything permitted by `vcr.VCR(**kwargs)` can be put here.)
@@ -116,6 +116,12 @@ def _base_vcr_config() -> dict:
116116

117117

118118
@pytest.fixture(scope="session")
119-
def vcr_config(_base_vcr_config: dict) -> dict:
119+
@deprecated("1.0.1", alternative="base_vcr_config", removal="2.0")
120+
def _base_vcr_config() -> dict:
121+
return base_vcr_config()
122+
123+
124+
@pytest.fixture(scope="session")
125+
def vcr_config() -> dict:
120126
"""VCR config fixture."""
121-
return _base_vcr_config
127+
return base_vcr_config()

libs/standard-tests/langchain_tests/integration_tests/chat_models.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,7 @@ def enable_vcr_tests(self) -> bool:
612612
613613
```python title="tests/conftest.py"
614614
import pytest
615-
from langchain_tests.conftest import (
616-
_base_vcr_config as _base_vcr_config,
617-
)
615+
from langchain_tests.conftest import base_vcr_config
618616
619617
_EXTRA_HEADERS = [
620618
# Specify additional headers to redact
@@ -629,9 +627,9 @@ def remove_response_headers(response: dict) -> dict:
629627
630628
631629
@pytest.fixture(scope="session")
632-
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
630+
def vcr_config() -> dict:
633631
"""Extend the default configuration from langchain_tests."""
634-
config = _base_vcr_config.copy()
632+
config = base_vcr_config()
635633
config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)
636634
config["before_record_response"] = remove_response_headers
637635
@@ -651,9 +649,7 @@ def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
651649
CustomPersister,
652650
CustomSerializer,
653651
)
654-
from langchain_tests.conftest import (
655-
_base_vcr_config as _base_vcr_config,
656-
)
652+
from langchain_tests.conftest import base_vcr_config
657653
from vcr import VCR
658654
659655
_EXTRA_HEADERS = [
@@ -669,9 +665,9 @@ def remove_response_headers(response: dict) -> dict:
669665
670666
671667
@pytest.fixture(scope="session")
672-
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
668+
def vcr_config() -> dict:
673669
"""Extend the default configuration from langchain_tests."""
674-
config = _base_vcr_config.copy()
670+
config = base_vcr_config()
675671
config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)
676672
config["before_record_response"] = remove_response_headers
677673
# New: enable serializer and set file extension

libs/standard-tests/langchain_tests/unit_tests/chat_models.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,7 @@ def enable_vcr_tests(self) -> bool:
705705
706706
```python title="tests/conftest.py"
707707
import pytest
708-
from langchain_tests.conftest import (
709-
_base_vcr_config as _base_vcr_config,
710-
)
708+
from langchain_tests.conftest import base_vcr_config
711709
712710
_EXTRA_HEADERS = [
713711
# Specify additional headers to redact
@@ -722,9 +720,9 @@ def remove_response_headers(response: dict) -> dict:
722720
723721
724722
@pytest.fixture(scope="session")
725-
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
723+
def vcr_config() -> dict:
726724
"""Extend the default configuration from langchain_tests."""
727-
config = _base_vcr_config.copy()
725+
config = base_vcr_config()
728726
config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)
729727
config["before_record_response"] = remove_response_headers
730728
@@ -744,9 +742,7 @@ def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
744742
CustomPersister,
745743
CustomSerializer,
746744
)
747-
from langchain_tests.conftest import (
748-
_base_vcr_config as _base_vcr_config,
749-
)
745+
from langchain_tests.conftest import base_vcr_config
750746
from vcr import VCR
751747
752748
_EXTRA_HEADERS = [
@@ -762,9 +758,9 @@ def remove_response_headers(response: dict) -> dict:
762758
763759
764760
@pytest.fixture(scope="session")
765-
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
761+
def vcr_config() -> dict:
766762
"""Extend the default configuration from langchain_tests."""
767-
config = _base_vcr_config.copy()
763+
config = base_vcr_config()
768764
config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)
769765
config["before_record_response"] = remove_response_headers
770766
# New: enable serializer and set file extension

0 commit comments

Comments
 (0)