Registry / llm-agents / langchain-tests

langchain-tests

JSON →
library1.1.6pypypiunverified

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.

pip install langchain-tests pytest
INSTALL
IMPORT
SIG · LANGCHAIN-TESTS
L
langchain-tests
llm-agentspythonv1.1.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.")
Debug
Known issues
gotchaThe `langchain-tests` package provides the actual test *implementations* and fixtures. However, the `StandardTestSuite` base class and general testing utilities (e.g., for creating mock integrations) that users extend to implement their own tests are typically found in `langchain-core` (e.g., `langchain_core.utils.standard_tests`).
fix
When building a new integration, derive your test classes from `langchain_core.utils.standard_tests.StandardTestSuite` and implement its abstract methods. Then, use `pytest` to discover and run your implementation alongside the standard `langchain-tests`.
affects: All versions
gotchaMany tests within `langchain-tests` (especially integration tests) require specific environment variables (e.g., `OPENAI_API_KEY`, `GOOGLE_API_KEY`, `ANTHROPIC_API_KEY`) and/or external service configurations to run successfully. Tests that cannot connect to required services or find necessary credentials will often be skipped.
fix
Consult the LangChain documentation for the specific integration you are testing to understand its environmental requirements. Ensure all necessary API keys and service endpoints are correctly configured as environment variables or passed during test setup.
affects: All versions
gotchaThe primary way to 'use' `langchain-tests` is by running `pytest` from the command line, allowing it to discover the contained test functions and modules. Direct programmatic imports of classes or functions from `langchain_tests` for use in application logic are generally not common or intended, as the package's purpose is testing.
fix
To execute the tests, use `pytest --pyargs langchain_tests` in your terminal. If you need to write custom tests for your integration, you'll typically interact with base classes and utilities from `langchain-core`.
affects: All versions
breaking`langchain-tests` is part of the `langchain` monorepo and has tight dependency coupling with `langchain-core` and other `langchain` packages. Incompatibility issues can arise if `langchain-tests` is used with significantly older or newer versions of `langchain-core`.
fix
Always install `langchain-tests` with a version that aligns with your `langchain-core` installation. Check the `pyproject.toml` of `langchain-tests` on GitHub for its exact `langchain-core` dependency range. It is often safest to upgrade both packages concurrently.
affects: Major version boundaries (e.x. `langchain-core` 0.x vs 1.x)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'langchain.retrievers'
This error typically occurs when importing modules from older LangChain package structures, as modules like 'langchain.retrievers' have been moved or refactored into more specific community or core packages (e.g., `langchain-community`).
fix
Update your import statements to reflect the new modular structure, for example, `from langchain_community.retrievers import ...` and ensure `langchain-community` is installed.
AttributeError: 'RunnableSequence' object has no attribute 'combine_documents_chain'
This error signifies an attempt to access a legacy attribute (`combine_documents_chain`) on a `RunnableSequence` object, which is part of LangChain Expression Language (LCEL) and does not expose internal components in the same way as older chain implementations.
fix
Refactor your code to use LCEL's recommended approach for chaining runnables and accessing their outputs, typically by invoking the `RunnableSequence` or accessing its dictionary output, rather than relying on legacy chain attributes. You might need to adjust your tests to interact with LCEL objects as opaque pipelines.
pydantic.v1.errors.ConfigError: unable to infer type for attribute "name"
This specific Pydantic v1 configuration error arises in Python 3.14 environments due to changes in typing or class creation that affect how Pydantic infers types, especially within `langchain-tests` when testing models.
fix
Explicitly define the type hints for attributes like 'name' in your Pydantic models being tested, or update `langchain-tests` and related `langchain-core` packages to versions compatible with Python 3.14 that address this Pydantic behavior.
ModuleNotFoundError: No module named 'qdrant_client'
This error occurs when running integration tests for a specific vector store (Qdrant in this case) but the necessary underlying client library (`qdrant-client`) has not been installed in the environment.
fix
Install the missing dependency using pip: `pip install qdrant-client`. Ensure all optional dependencies required by the integration you are testing are installed.
Upgrade
Version history
1.1.6latest on PyPI · released Apr 8, 2026
Audit
Dependencies
langchain-corerequiredProvides core abstractions and utilities, including the `StandardTestSuite` base class which these tests often target or extend.
pytestrequiredThe primary test runner used to discover and execute the tests provided by `langchain-tests`.
pydanticrequiredUsed extensively by `langchain-core` for data validation and settings management, which is foundational for tests.
pytest-asynciorequiredRequired for running asynchronous tests using pytest.
Agent activity
32 hits · last 30 days
node
28
OpenAI (training)
1
Resources
langchain-tests — pip install langchain-tests · libregistry