Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

syrupy

БесплатноБез исполняемых скриптовНе проверен

Use syrupy for pytest snapshot testing to ensure the immutability of computed results, manage snapshots, customize serialization, and handle complex data…

anam-orgот anam-org★ 127 звёзд на GitHub17 установок в других каталогах

Об этом скилле

Syrupy - Pytest Snapshot Testing

Syrupy is a zero-dependency pytest snapshot testing plugin that enables asserting the immutability of computed results through simple, idiomatic assertions.

Docs: https://syrupy-project.github.io/syrupy/

What is Syrupy?

Syrupy is a snapshot testing library that:

  • Captures the output/state of code at a point in time
  • Compares future test runs against saved snapshots
  • Automatically manages snapshot files in __snapshots__ directories
  • Integrates naturally with pytest's assertion syntax

Core Philosophy

Three Design Principles:

  1. Extensible: Easy to add support for custom/unsupported data types
  2. Idiomatic: Natural pytest-style assertions (assert x == snapshot)
  3. Sound: Fails tests if snapshots are missing or different

Target Use Case: Testing complex data structures, API responses, UI components, or any computed results that should remain stable over time.

Snapshot Fixture API

Core Methods

The snapshot fixture accepts several options per assertion:

  • matcher: Control how objects are serialized
  • exclude: Filter out properties from snapshots
  • include: Include only specific properties
  • extension_class: Use a different serialization format
  • diff: Capture only differences from a base
  • name: Custom name for the snapshot

Usage with Options

assert data == snapshot(matcher=my_matcher, exclude=my_filter, name="custom_name")

Built-in Extensions

Syrupy provides several snapshot extensions for different use cases:

AmberSnapshotExtension (Default)

  • Human-readable format
  • Stores all snapshots in .ambr files
  • Supports all Python built-in types
  • Custom object representation via __repr__

JSONSnapshotExtension

  • Stores snapshots as JSON files (.json extension)
  • Useful for API responses and complex data structures
  • Machine-readable format
  • Import from syrupy.extensions.json

Usage Example:

import pytest
from syrupy.extensions.json import JSONSnapshotExtension


@pytest.fixture
def snapshot_json(snapshot):
    return snapshot.use_extension(JSONSnapshotExtension)


def test_api_call(client, snapshot_json):
    resp = client.post("/endpoint")
    assert resp.status_code == 200
    assert snapshot_json == resp.json()

Handling Dynamic Data in JSON:

from datetime import datetime
from syrupy.matchers import path_type


def test_api_call(client, snapshot_json):
    resp = client.post("/user", json={"name": "Jane"})
    matcher = path_type({"id": (int,), "registeredAt": (datetime,)})
    assert snapshot_json(matcher=matcher) == resp.json()

SingleFileSnapshotExtension

  • One file per snapshot
  • Configurable file extensions
  • Useful for binary data or large snapshots

PNGSnapshotExtension

  • For image snapshot testing
  • Compares PNG image data

SVGSnapshotExtension

  • For SVG vector graphics
  • Text-based comparison of SVG content

Matchers

Matchers control how specific values are serialized during snapshot creation.

path_type

Match specific paths in data structures to types:

from syrupy.matchers import path_type
import datetime

matcher = path_type({"date_created": (datetime,), "user.id": (int,), "nested.*.timestamp": (datetime,)})

path_value

Match paths and replace with specific values:

from syrupy.matchers import path_value

matcher = path_value({"id": "REDACTED_ID", "token": "***"})

Filters

Filters control which properties are included/excluded from snapshots.

Custom Exclude Function

The exclude parameter accepts a custom filter function with this signature:

def my_filter(prop, path):
    """
    Args:
        prop: The current property (any hashable value: int, str, object, etc.)
        path: Ordered sequence of traversed locations, e.g.,
              (("a", dict), ("b", dict)) when navigating {"a": {"b": {"c": 1}}}

    Returns:
        True to exclude the property, False to include it
    """
    return should_exclude

Example:

def limit_foo_attrs(prop, path):
    allowed_attrs = {"only", "serialize", "these", "attrs"}
    return isinstance(path[-1][1], Foo) and prop in allowed_attrs


def test_bar(snapshot):
    actual = Foo(...)
    assert actual == snapshot(exclude=limit_foo_attrs)

props

Filter by property names (shallow):

from syrupy.filters import props

# Exclude specific properties
exclude = props("id", "timestamp", "random_value")

# Include only specific properties
include = props("name", "type", "data")

# Works with indexed iterables
exclude = props("id", "1")  # Excludes "id" and index 1

paths

Filter by full property paths using dot-delimited strings:

from syrupy.filters import paths

# Exclude nested paths
exclude = paths("user.password", "response.headers.authorization", "items.*.id")

# Works with list indices
exclude = paths("date", "list.1")

CLI Options

Syrupy adds sev

Полный SKILL.md на GitHub

Установить syrupy в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

EXAMPLES.md

FAQ

Что делает скилл syrupy?

Use syrupy for pytest snapshot testing to ensure the immutability of computed results, manage snapshots, customize serialization, and handle complex data structures with built-in matchers and filters.

Как установить скилл syrupy?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл syrupy запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить syrupy с