Implementation:Langchain ai Langchain BaseStoreTests
| Knowledge Sources | |
|---|---|
| Domains | Testing, Key-Value Store, Standard Tests |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Standard integration test suites for validating synchronous and asynchronous implementations of the LangChain BaseStore key-value abstraction.
Description
This module provides two abstract test suite classes -- BaseStoreSyncTests and BaseStoreAsyncTests -- in the langchain-tests (standard-tests) package. They verify that implementations of BaseStore[str, V] from langchain-core correctly support the key-value store API including mget, mset, mdelete, and yield_keys operations. Implementers subclass one or both suites and provide pytest fixtures that return an empty store and three example values.
Usage
Import BaseStoreSyncTests or BaseStoreAsyncTests when writing integration tests for a custom BaseStore implementation to ensure it conforms to the standard key-value store contract.
Code Reference
Source Location
- Repository: Langchain_ai_Langchain
- File: libs/standard-tests/langchain_tests/integration_tests/base_store.py
- Lines: 1-315
Signature
class BaseStoreSyncTests(BaseStandardTests, Generic[V]):
@abstractmethod
@pytest.fixture
def kv_store(self) -> BaseStore[str, V]: ...
@abstractmethod
@pytest.fixture
def three_values(self) -> tuple[V, V, V]: ...
class BaseStoreAsyncTests(BaseStandardTests, Generic[V]):
@abstractmethod
@pytest.fixture
async def kv_store(self) -> BaseStore[str, V]: ...
@abstractmethod
@pytest.fixture
def three_values(self) -> tuple[V, V, V]: ...
Import
from langchain_tests.integration_tests.base_store import (
BaseStoreSyncTests,
BaseStoreAsyncTests,
)
I/O Contract
Inputs (Fixtures)
| Name | Type | Required | Description |
|---|---|---|---|
| kv_store | BaseStore[str, V] | Yes | An empty key-value store instance to test. Must be empty at the start of each test. |
| three_values | tuple[V, V, V] | Yes | Three example values of type V that will be used in the tests. |
Outputs
| Name | Type | Description |
|---|---|---|
| Test results | pytest outcomes | Pass/fail results for each standard test method. |
Test Methods (BaseStoreSyncTests)
| Test Method | Description |
|---|---|
| test_three_values | Verifies that the fixture provides exactly three values in a tuple. |
| test_kv_store_is_empty | Verifies the store starts empty (mget returns [None, None, None]). |
| test_set_and_get_values | Tests mset followed by mget for two key-value pairs. |
| test_store_still_empty | Verifies the fixture resets the store to empty between tests. |
| test_delete_values | Tests mdelete removes a single key while preserving others. |
| test_delete_bulk_values | Tests bulk deletion of multiple keys at once. |
| test_delete_missing_keys | Verifies deleting non-existent keys does not raise exceptions. |
| test_set_values_is_idempotent | Verifies setting the same keys twice does not duplicate entries. |
| test_get_can_get_same_value | Tests retrieving the same key multiple times in a single mget call. |
| test_overwrite_values_by_key | Tests that mset overwrites existing values for the same key. |
| test_yield_keys | Tests yield_keys returns all keys and supports prefix filtering. |
Test Methods (BaseStoreAsyncTests)
The async suite mirrors the sync suite with equivalent tests using amget, amset, amdelete, and ayield_keys async methods.
Usage Examples
Basic Usage
import pytest
from langchain_core.stores import BaseStore
from langchain_tests.integration_tests.base_store import BaseStoreSyncTests
from my_package.stores import MyKeyValueStore
class TestMyKeyValueStore(BaseStoreSyncTests[str]):
@pytest.fixture
def kv_store(self) -> BaseStore[str, str]:
store = MyKeyValueStore()
# Ensure the store is empty
return store
@pytest.fixture
def three_values(self) -> tuple[str, str, str]:
return ("value1", "value2", "value3")