# syrupy (pytest)

> Send syrupy snapshot files to VisualCI, so a changed snapshot waits for review instead of failing pytest.

Source: https://visualci.com/docs/snapshots/syrupy/
All of VisualCI's documentation: https://visualci.com/llms.txt

syrupy writes `.ambr` files to a `__snapshots__` directory next to each test file. VisualCI splits them into one snapshot per test.

## 1. Stop committing snapshot files

The baselines live on VisualCI, so the snapshot files don't belong in git. Add them to `.gitignore`:

```gitignore
__snapshots__/
```

Then remove the committed copies (`git rm -r --cached` on those paths). In a new project, the first build has nothing to compare against and becomes the baseline. In a project that already has builds, the snapshots show as added the first time, for your agent to approve once.

## 2. Write snapshots instead of failing

Run pytest with `--snapshot-update`, locally and in CI:

```sh
pytest --snapshot-update
```

syrupy fails a test whose snapshot is missing, and with no snapshot files in the checkout every snapshot is missing. `--snapshot-update` writes them all (and deletes unused ones), so the run only fails on real test failures. VisualCI does the comparing.

## 3. Upload after the tests

In the CI job, after the tests (see [Quick start](https://visualci.com/docs/quick-start.md) for creating the build):

```sh
visualci upload --from syrupy tests
visualci build finalize
```

Snapshot names are the file's path without `__snapshots__/` and the extension, then the test's name. `--from auto` detects each file's framework, for repositories with several.

When a snapshot changed, CI still passes and the pull request's check waits. Your coding agent reads the change with `get_snapshot`, which shows text snapshots as a unified diff and JSON as changes by path (`items[3].price: 10 → 12`), then approves it or fixes the code. See [Coding agents](https://visualci.com/docs/agents.md).

## Ignore volatile values

Timestamps, generated IDs and other values that change on every run would show up as changes. Ignore them per project, on the project's **Settings** tab or with `update_project` over MCP:

- `json_paths` for JSON snapshots: `$.generated_at`, `$.items[*].id`, `$..request_id`;
- `text_patterns`, regular expressions for every text snapshot, such as `\d{4}-\d{2}-\d{2}`.

Matching values are replaced with `[ignored]` before comparing.

## Before you push

`visualci check` runs the same comparison from your laptop:

```sh
pytest --snapshot-update && visualci check --from syrupy tests
```

It creates a local build, waits for the result and prints what changed, with a link to the diff. Local builds can be viewed but not approved yet: the change is approved on the CI build of the pushed commit.
