All skills
lexler avatar

/approval-tests

@83aee6a
by Lada Kesselerlexler/skill-factory238 stars
61

Writes approval tests (snapshot/golden master testing) for Python, JavaScript/TypeScript, or Java. Use when verifying complex output, characterization testing legacy code, testing combinations, or working with .approved/.received files.

Use this Skill: https://skilld.dev/gh/lexler/skill-factory/approval-tests

This session only. Nothing lands on disk.

python.md

≈755 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Python ApprovalTests

Installation

pip install approvaltests

Quick Start

from approvaltests import verify

def test_report():
    result = generate_report()
    verify(result)

First run fails and creates two files:

  • test_file.test_report.received.txt - actual output
  • test_file.test_report.approved.txt - empty (the expectation)

Review .received, if correct, copy to .approved. Rerun → passes.

Recommended Imports

from approvaltests import verify, verify_as_json, verify_all, Options
from approvaltests.scrubbers import scrub_all_guids, scrub_all_dates, create_regex_scrubber

Core Patterns

verify_as_json() - Objects (preferred for structured data)

from approvaltests import verify_as_json

def test_user():
    user = get_user(123)
    verify_as_json(user)

Produces readable, diff-friendly JSON. Use this for any object, dict, or list.

verify_all() - Collections with labels

from approvaltests import verify_all

def test_users():
    users = get_all_users()
    verify_all("Users", users, lambda u: f"{u.name}: {u.email}")

Scrubbing timestamps, GUIDs, random values

from approvaltests import verify, Options
from approvaltests.scrubbers import scrub_all_dates, scrub_all_guids

def test_api_response():
    response = call_api()
    options = Options().with_scrubber(scrub_all_dates).add_scrubber(scrub_all_guids)
    verify(response, options=options)

Always add scrubbers BEFORE the first test run, not after CI fails.

Combination testing

from approvaltests import verify_all_combinations_with_labeled_input

def test_pricing():
    verify_all_combinations_with_labeled_input(
        calculate_price,
        size=["S", "M", "L"],
        color=["red", "blue"],
        express=[True, False],
    )

Tests all 12 combinations in one approval file.

Multiple scenarios per test

NamerFactory.with_parameters() creates separate approval files per scenario. See patterns.md.

Git Setup

*.received.*

Commit all .approved.* files.

Reference Files

  • api.md - verify_xml/html/binary, Storyboard, MarkdownTable, Options methods
  • scrubbers.md - Custom date formats, regex patterns, combining scrubbers, line removal
  • combinations.md - Input combinations, pairwise testing, exception handling
  • patterns.md - Characterization tests, multiple approvals per test, common mistakes
  • inline.md - Expectations in docstrings instead of .approved files
  • logging.md - Log output verification, SimpleLogger method tracing
  • reporters.md - Custom diff tools, reporter chains
  • setup.md - CI troubleshooting, pytest config, approval file locations

Source: SKILL.md on GitHub

1 warning6d4 checks · Risk SAFE
  • Gen Agent Trust Hub6d

    The skill provides instructions and patterns for implementing approval testing (snapshot testing) across multiple programming languages. It includes capabilities for file system operations, command execution for testing CLI tools, and launching external diff reporters, which are consistent with the skill's purpose. The analysis identified an indirect prompt injection surface when verifying external or untrusted data.

  • Socket6d

    No alerts

  • Snyk6d

    Risk: LOW · No issues

  • Runlayer7mo

    25/25 files flagged

Signed by skilld at 83aee6a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 8 months ago

README badge

README badge for lexler/skill-factory/approval-tests