Setup
Install Braintrust alongside pytest:Run your first eval
Mark tests with@pytest.mark.braintrust, accept the braintrust_span fixture, and run pytest with --braintrust.
test_my_llm.py
How it works
@pytest.mark.braintrustopts a test into Braintrust tracking.braintrust_spangives you a standard Braintrust span for logging input, output, scores, metadata, and errors.--braintrustenables experiment tracking for the session.--braintrust-projectandproject=...on the marker control how tests are grouped into projects and experiments.
--braintrust is not provided, braintrust_span becomes a no-op span, so the same tests still run as normal unit tests.
Parametrized tests
Pytest parameters are logged automatically asinput unless you override them in the marker.
test_math.py
CLI options
| Option | Description |
|---|---|
--braintrust | Enable Braintrust experiment tracking |
--braintrust-project | Override the project name for all tracked tests |
--braintrust-experiment | Override the experiment name |
--braintrust-api-key | Provide the Braintrust API key on the command line |
--braintrust-no-summary | Suppress the terminal experiment summary |
What to log
Thebraintrust_span fixture supports normal span logging methods. Typical fields to capture are:
inputfor the prompt or test payloadoutputfor the model responseexpectedfor the target behaviorscoresfor custom metrics beyond pass or failmetadatafor model name, environment, or fixture details