设置
首先,安装所需的依赖项:langchain-tests package:
Unit tests
Unit tests
Location:
langchain_tests.unit_testsDesigned to test the component in isolation and without access to external servicesView API referenceIntegration tests
Integration tests
Location:
langchain_tests.integration_testsDesigned to test the component with access to external services (in particular, the external service that the component is designed to interact with)View API referencepytest class-based test suites.
Implementing standard tests
Depending on your integration type, you will need to implement either or both unit and integration tests. By subclassing the standard test suite for your integration type, you get the full collection of standard tests for that type. For a test run to be successful, the a given test should pass only if the model supports the capability being tested. Otherwise, the test should be skipped. Because different integrations offer unique sets of features, most standard tests provided by LangChain are opt-in by default to prevent false positives. Consequently, you will need to override properties to indicate which features your integration supports - see the below example for an illustration.tests/integration_tests/test_standard.py
You should organize tests in these subdirectories relative to the root of your package:
tests/unit_testsfor unit teststests/integration_testsfor integration tests
- Unit tests
- Integration tests
Running tests
If bootstrapping an integration from a template, aMakefile is provided that includes targets for running unit and integration tests: