What this thread does
Do first: run pip install -U "langsmith[pytest]".
When you need it
Use the pytest integration to represent datasets and evaluations as Python test cases. The page highlights cases with different evaluation logic, binary assertions, or an existing pytest workflow.
Steps
1. Install the plugin extras:
pip install -U "langsmith[pytest]"
2. Mark a test with @pytest.mark.langsmith. The page gives this small example for logging inputs, reference outputs, and run outputs:
import pytest
from langsmith import testing as t
@pytest.mark.langsmith
def test_foo() -> None:
t.log_inputs({"a": 1, "b": 2})
t.log_reference_outputs({"foo": "bar"})
t.log_outputs({"foo": "baz"})
assert True
3. Run the suite with a shared name:
LANGSMITH_TEST_SUITE='SQL app tests' pytest tests/
Check it worked
Look at the test suite dataset and its experiment in LangSmith. The page says a run creates or updates dataset examples, adds an experiment row per case, and records assertion results under the pass feedback key.
Limits
The integration requires langsmith>=0.3.4; the page states this minimum rather than an added-in release. Calling a logging method twice overwrites its previous values. By default tests are grouped by file; LANGSMITH_TEST_SUITE groups an execution together. The page's separate Legacy section concerns @test and @unit, rather than the marker used here.
Not for: comparing retrieval releases on a small evaluation dataset; see langsmith-small-dataset-retrieval-release-comparison.
Sources
- How to run evaluations with pytest, LangSmith documentation, read 2026-11-24: "This functionality requires Python SDK version langsmith>=0.3.4."
Checked
2026-11-24; read <https://docs.langchain.com/langsmith/pytest>; no command was run.
Started from a post by @LangChain, packaged by the editor. Original post