CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-syrupy

Pytest snapshot testing utility that enables developers to write tests asserting immutability of computed results.

Overall
score

80%

Overview
Eval results
Files

task.mdevals/scenario-4/

Snapshot Defaults Harness

Configure snapshot testing defaults so snapshot files share the same serialization, storage location, and output style across a test session.

Capabilities

Persisted snapshot defaults

  • A helper produces a snapshot assertion variant that keeps a provided matcher and excluded keys as defaults across multiple assertions in one test, so repeated uses do not need to restate those options. @test
  • Using that helper, two payloads with dynamic timestamps and private fields both assert successfully while the stored snapshots omit the excluded keys and replace timestamps through the default matcher. @test

CLI-driven defaults

  • When the test suite is invoked with command-line arguments that set the default snapshot extension to JSON and the snapshot directory name to snapshots_alt, newly written snapshots for a sample payload are placed under that directory with a .json extension. @test

Colorless diffs on demand

  • When running the suite with color output disabled via command-line configuration, a deliberately failing snapshot assertion yields diff output with no ANSI color codes. @test

Implementation

@generates

API

from typing import Any, Callable

ConfiguredSnapshot = Any

def make_persisted_snapshot(
    base_snapshot: Any,
    *,
    matcher: Callable[..., Any],
    exclude_fields: tuple[str, ...],
) -> ConfiguredSnapshot:
    """
    Return a snapshot assertion variant that keeps the matcher and exclusions
    as defaults across multiple uses within a test.
    """

def capture_payloads(snapshot: ConfiguredSnapshot, *payloads: Any) -> list[Any]:
    """
    Assert each payload against the configured snapshot variant in order and
    return the payloads after assertion.
    """

Dependencies { .dependencies }

syrupy { .dependency }

Python snapshot testing library for pytest; provides the snapshot assertion fixture, global defaults configuration, and CLI options for extension, directory naming, and color handling.

Install with Tessl CLI

npx tessl i tessl/pypi-syrupy

tile.json