Skip to content

Commit 1d35677

Browse files
committed
tests(fixtures): provide JSON/YAML syrupy snapshot fixtures
1 parent 97d02d0 commit 1d35677

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Shared pytest fixtures for snapshot testing."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
from syrupy.assertion import SnapshotAssertion
7+
from syrupy.extensions.json import JSONSnapshotExtension
8+
from syrupy.extensions.single_file import SingleFileSnapshotExtension, WriteMode
9+
10+
11+
class YamlSnapshotExtension(SingleFileSnapshotExtension):
12+
"""Snapshot extension that persists plain-text YAML files."""
13+
14+
file_extension = "yaml"
15+
_write_mode = WriteMode.TEXT
16+
17+
18+
@pytest.fixture
19+
def snapshot_json(snapshot: SnapshotAssertion) -> SnapshotAssertion:
20+
"""JSON-formatted snapshot assertions."""
21+
return snapshot.with_defaults(extension_class=JSONSnapshotExtension)
22+
23+
24+
@pytest.fixture
25+
def snapshot_yaml(snapshot: SnapshotAssertion) -> SnapshotAssertion:
26+
"""YAML-formatted snapshot assertions."""
27+
return snapshot.with_defaults(extension_class=YamlSnapshotExtension)

0 commit comments

Comments
 (0)