Skip to navigation

Sync test suites from a file

Keep your test cases in a file next to your code
View as Markdown

You can keep the test cases of a test suite in a JSON or YAML file next to your agent code. You then change test cases in the same pull request as the code, and suite.sync makes the suite match the file before each run.

Write the file

The file has an items list, with the same item format as suite.insert. It can also set the suite-level assertions and execution policy:

suite.yaml
global_assertions:
- The response is grounded in the provided context
global_execution_policy:
runs_per_item: 1
pass_threshold: 1
items:
- description: Project creation question
data:
question: How do I create a new project?
context: To create a new project, go to the Dashboard and click 'New Project'.
assertions:
- The response explains where to click

YAML files need pyyaml:

pip install pyyaml

Sync the suite

Call suite.sync with the path to the file, for example at the start of your test run:

Python
import opik
suite = opik.Opik().get_or_create_test_suite(name="support-agent", project_name="my-project")
suite.sync("suite.yaml")

You can also pass a list of items, with global_assertions and global_execution_policy as arguments:

Python
suite.sync(
[
{
"data": {"question": "How do I create a new project?"},
"assertions": ["The response explains where to click"],
},
],
global_assertions=["The response is grounded in the provided context"],
)

How changes are matched

sync matches the test cases of the suite and the file on their data:

  • A test case with the same data keeps its id, so its experiment history continues. Its assertions, description and execution policy are updated if they changed.
  • A test case with new or changed data is added as a new test case.
  • A test case that is no longer in the file is deleted.

All changes go into one new suite version, and no version is created when nothing changed. So you can call sync before every run.

Next steps