{"id":2983,"library":"langchain-tests","title":"LangChain Standard Tests","description":"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.","status":"active","version":"1.1.6","language":"en","source_language":"en","source_url":"https://github.com/langchain-ai/langchain/tree/main/libs/standard-tests","tags":["testing","langchain","LLM","AI"],"install":[{"cmd":"pip install langchain-tests pytest","lang":"bash","label":"Install library and test runner"}],"dependencies":[{"reason":"Provides core abstractions and utilities, including the `StandardTestSuite` base class which these tests often target or extend.","package":"langchain-core"},{"reason":"The primary test runner used to discover and execute the tests provided by `langchain-tests`.","package":"pytest"},{"reason":"Used extensively by `langchain-core` for data validation and settings management, which is foundational for tests.","package":"pydantic"},{"reason":"Required for running asynchronous tests using pytest.","package":"pytest-asyncio"}],"imports":[],"quickstart":{"code":"import pytest\nimport sys\n\n# This script demonstrates how to programmatically run tests from the langchain-tests package.\n# In practice, you would typically run 'pytest' directly from your terminal.\n\n# Ensure langchain-tests and pytest are installed:\n# pip install langchain-tests pytest\n\n# To run all tests within the 'langchain_tests' package:\n# Use '--pyargs' to treat the target as a Python package, allowing pytest to discover tests.\ntest_target = \"langchain_tests\" \n\nprint(f\"Running tests for target: {test_target}\")\n\n# pytest.main() returns an exit code. sys.exit() uses this code.\n# -v for verbose output.\nexit_code = pytest.main([\"-v\", \"--pyargs\", test_target])\n\nif exit_code != 0:\n    print(f\"Tests failed with exit code {exit_code}\")\nelse:\n    print(\"All specified tests passed!\")\n\n# You can also run specific test modules:\n# exit_code_specific = pytest.main([\"-v\", \"--pyargs\", \"langchain_tests.unit_tests.test_retrievers\"])\n# if exit_code_specific != 0: print(\"Specific retriever tests failed.\")","lang":"python","description":"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."},"warnings":[{"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`.","message":"The `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`).","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Many 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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"`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`.","severity":"breaking","affected_versions":"Major version boundaries (e.x. `langchain-core` 0.x vs 1.x)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}