Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit test nits #581

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions docs/evaluation/how_to_guides/unit_testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Loading