> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.comet.com/docs/opik/llms.txt.

# Sync test suites from a file

You can keep the test cases of a [test suite](/docs/opik/evaluation/advanced/building-test-suites) 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`**

```yaml title="suite.yaml" maxLines=1000 wordWrap
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`:

```bash
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`**

```python title="Python" wordWrap
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`**

```python title="Python" wordWrap
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](/docs/opik/evaluation/advanced/test_case_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

* [Building test suites](/docs/opik/evaluation/advanced/building-test-suites)
* [Evaluate multi-turn agents](/docs/opik/evaluation/evaluate_multi_turn_agents)
* [Manage datasets](/docs/opik/evaluation/advanced/manage_datasets)