LangChain Standard Tests

1.1.6 · active · verified Sat Apr 11

langchain-tests provides a collection of standard unit and integration tests designed for verifying LangChain implementations and integrations. It ensures consistent behavior across various components (e.g., LLMs, ChatModels, Embeddings, Retrievers). The library is part of the broader LangChain ecosystem and sees frequent updates, typically alongside `langchain-core` releases. The current version is 1.1.6.

Warnings

Install

Quickstart

The primary way to use `langchain-tests` is by running `pytest` to discover and execute its test modules. This example shows how to programmatically invoke `pytest` to run all tests within the `langchain_tests` package.

import pytest
import sys

# This script demonstrates how to programmatically run tests from the langchain-tests package.
# In practice, you would typically run 'pytest' directly from your terminal.

# Ensure langchain-tests and pytest are installed:
# pip install langchain-tests pytest

# To run all tests within the 'langchain_tests' package:
# Use '--pyargs' to treat the target as a Python package, allowing pytest to discover tests.
test_target = "langchain_tests" 

print(f"Running tests for target: {test_target}")

# pytest.main() returns an exit code. sys.exit() uses this code.
# -v for verbose output.
exit_code = pytest.main(["-v", "--pyargs", test_target])

if exit_code != 0:
    print(f"Tests failed with exit code {exit_code}")
else:
    print("All specified tests passed!")

# You can also run specific test modules:
# exit_code_specific = pytest.main(["-v", "--pyargs", "langchain_tests.unit_tests.test_retrievers"])
# if exit_code_specific != 0: print("Specific retriever tests failed.")

view raw JSON →