syrupy
БесплатноБез исполняемых скриптовНе проверенUse syrupy for pytest snapshot testing to ensure the immutability of computed results, manage snapshots, customize serialization, and handle complex data…
Об этом скилле
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:
- Extensible: Easy to add support for custom/unsupported data types
- Idiomatic: Natural pytest-style assertions (
assert x == snapshot) - 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 serializedexclude: Filter out properties from snapshotsinclude: Include only specific propertiesextension_class: Use a different serialization formatdiff: Capture only differences from a basename: 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
.ambrfiles - Supports all Python built-in types
- Custom object representation via
__repr__
JSONSnapshotExtension
- Stores snapshots as JSON files (
.jsonextension) - 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
Установить syrupy в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
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), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic