standard-tests[patch]: Add pytest assert rewrites (#24408)

This will surface nice error messages in subclasses that fail assertions.
This commit is contained in:
Eugene Yurtsev 2024-07-18 17:41:11 -04:00 committed by GitHub
parent f62b323108
commit ef22ebe431
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 62 additions and 0 deletions

View File

@ -1,6 +1,35 @@
from typing import Tuple
import pytest
from langchain_standard_tests.integration_tests.base_store import (
BaseStoreAsyncTests,
BaseStoreSyncTests,
)
from langchain_core.stores import InMemoryStore
# Check against standard tests
class TestSyncInMemoryStore(BaseStoreSyncTests):
@pytest.fixture
def kv_store(self) -> InMemoryStore:
return InMemoryStore()
@pytest.fixture
def three_values(self) -> Tuple[str, str, str]: # type: ignore
return "value1", "value2", "value3"
class TestAsyncInMemoryStore(BaseStoreAsyncTests):
@pytest.fixture
async def kv_store(self) -> InMemoryStore:
return InMemoryStore()
@pytest.fixture
def three_values(self) -> Tuple[str, str, str]: # type: ignore
return "value1", "value2", "value3"
def test_mget() -> None:
store = InMemoryStore()
store.mset([("key1", "value1"), ("key2", "value2")])

View File

@ -1,3 +1,21 @@
# ruff: noqa: E402
import pytest
# Rewrite assert statements for test suite so that implementations can
# see the full error message from failed asserts.
# https://docs.pytest.org/en/7.1.x/how-to/writing_plugins.html#assertion-rewriting
modules = [
"base_store",
"cache",
"chat_models",
"vectorstores",
]
for module in modules:
pytest.register_assert_rewrite(
f"langchain_standard_tests.integration_tests.{module}"
)
from langchain_standard_tests.integration_tests.chat_models import (
ChatModelIntegrationTests,
)

View File

@ -1,4 +1,5 @@
"""Test suite to test vectostores."""
import inspect
from abc import ABC, abstractmethod

View File

@ -1,3 +1,16 @@
# ruff: noqa: E402
import pytest
# Rewrite assert statements for test suite so that implementations can
# see the full error message from failed asserts.
# https://docs.pytest.org/en/7.1.x/how-to/writing_plugins.html#assertion-rewriting
modules = [
"chat_models",
]
for module in modules:
pytest.register_assert_rewrite(f"langchain_standard_tests.unit_tests.{module}")
from langchain_standard_tests.unit_tests.chat_models import ChatModelUnitTests
__all__ = ["ChatModelUnitTests"]

View File

@ -1,4 +1,5 @@
"""Tests for the InMemoryStore class."""
from typing import Tuple
import pytest