forked from Archives/langchain
6dc86ad48f
Using `pytest-vcr` in integration tests has several benefits. Firstly, it removes the need to mock external services, as VCR records and replays HTTP interactions on the fly. Secondly, it simplifies the integration test setup by eliminating the need to set up and tear down external services in some cases. Finally, it allows for more reliable and deterministic integration tests by ensuring that HTTP interactions are always replayed with the same response. Overall, `pytest-vcr` is a valuable tool for simplifying integration test setup and improving their reliability This commit adds the `pytest-vcr` package as a dependency for integration tests in the `pyproject.toml` file. It also introduces two new fixtures in `tests/integration_tests/conftest.py` files for managing cassette directories and VCR configurations. In addition, the `tests/integration_tests/vectorstores/test_elasticsearch.py` file has been updated to use the `@pytest.mark.vcr` decorator for recording and replaying HTTP interactions. Finally, this commit removes the `documents` fixture from the `test_elasticsearch.py` file and replaces it with a new fixture defined in `tests/integration_tests/vectorstores/conftest.py` that yields a list of documents to use in any other tests. This also includes my second attempt to fix issue : https://github.com/hwchase17/langchain/issues/2386 Maybe related https://github.com/hwchase17/langchain/issues/2484
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import os
|
|
|
|
import pytest
|
|
|
|
# Getting the absolute path of the current file's directory
|
|
ABS_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
# This fixture returns a string containing the path to the cassette directory for the
|
|
# current module
|
|
@pytest.fixture(scope="module")
|
|
def vcr_cassette_dir(request: pytest.FixtureRequest) -> str:
|
|
return os.path.join(
|
|
os.path.dirname(request.module.__file__),
|
|
"cassettes",
|
|
os.path.basename(request.module.__file__).replace(".py", ""),
|
|
)
|
|
|
|
|
|
# This fixture returns a dictionary containing filter_headers options
|
|
# for replacing certain headers with dummy values during cassette playback
|
|
# Specifically, it replaces the authorization header with a dummy value to
|
|
# prevent sensitive data from being recorded in the cassette.
|
|
@pytest.fixture(scope="module")
|
|
def vcr_config() -> dict:
|
|
return {
|
|
"filter_headers": [
|
|
("authorization", "authorization-DUMMY"),
|
|
("X-OpenAI-Client-User-Agent", "X-OpenAI-Client-User-Agent-DUMMY"),
|
|
("User-Agent", "User-Agent-DUMMY"),
|
|
],
|
|
}
|