-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,26 @@ sidebar_position: 7 | |
|
||
# How to unit test applications (Python only) | ||
|
||
LangSmith functional tests are assertions and expectations designed to **quickly** identify obvious bugs and regressions in your AI system. Relative to evaluations, tests typically are designed to be **fast** and **cheap** to run, focusing on **specific** functionality and edge cases. | ||
LangSmith functional tests are assertions and expectations designed to **quickly** identify obvious bugs and regressions in your AI system. | ||
Relative to evaluations, tests typically are designed to be **fast** and **cheap** to run, focusing on **specific** functionality and edge cases with binary assertions. | ||
We recommend using LangSmith to track any unit tests, end-to-end integration tests, or other specific assertions that touch an LLM or other non-deterministic part of your AI system. | ||
These should run on every commit in your CI pipeline to catch regressions early. | ||
Ideally these run on every commit in your CI pipeline to catch regressions early. | ||
|
||
:::note | ||
`@unit` currently requires `langsmith` python version `>=0.1.74` (named `@unit` for versions `>=0.1.42`). If you are interested in unit testing functionality in TypeScript or other languages, please let us know at [[email protected]](mailto:[email protected]). | ||
:::info Version requirement | ||
`@unit` requires `langsmith` Python version `>=0.1.74`. | ||
::: | ||
|
||
:::info TypeScript support | ||
If you are interested in unit testing functionality in TypeScript or other languages, please upvote/comment on [this GitHub Issue](https://github.com/langchain-ai/langsmith-sdk/issues/1321). | ||
::: | ||
|
||
## Write a @unit | ||
|
||
To write a LangSmith functional test, decorate your test function with `@unit`. | ||
If you want to track the full nested trace of the system or component being tested, you can mark those functions with `@traceable`. For example: | ||
|
||
```python | ||
my_app/main.py | ||
```python | ||
# my_app/main.py | ||
from langsmith import traceable | ||
|
||
@traceable # Optional | ||
|
@@ -30,8 +35,8 @@ def generate_sql(user_query): | |
|
||
Then define your test: | ||
|
||
```python tests/test_my_app.py | ||
tests/test_my_app.py | ||
```python | ||
# tests/test_my_app.py | ||
from langsmith import unit | ||
from my_app.main import generate_sql | ||
|
||
|