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.

referencespythoninline.md

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

Python Inline Approvals

Store expected output in the test's docstring instead of separate .approved files. Helps solve the problem of "there's too many approved files" when the approved output is small.

Contents

Basic Usage

from approvaltests import verify, Options

def test_fizz_buzz():
    """
    1
    2
    Fizz
    4
    Buzz
    """
    verify(fizz_buzz(5), options=Options().inline())

The docstring IS the approved output. When the test runs:

  • Output matches docstring: pass
  • Output differs: reporter shows diff, can auto-update docstring

InlineOptions

from approvaltests import verify, Options
from approvaltests.inline.inline_options import InlineOptions

# Automatic - auto-approves without confirmation
verify(result, options=Options().inline(InlineOptions.automatic()))

# Semi-automatic - adds marker you must delete to approve
verify(result, options=Options().inline(InlineOptions.semi_automatic()))

# Shows previous alongside new
verify(result, options=Options().inline(InlineOptions.semi_automatic_with_previous_approved()))

Semi-Automatic Marker

When using semi_automatic(), the docstring gets a marker:

def test_example():
    """
    new result here
    ***** DELETE ME TO APPROVE *****
    """

Delete the marker line to approve.

Parse Class

For input/output mapping tests:

from approvaltests.inline.parse import Parse

def test_uppercase():
    """
    hello -> HELLO
    world -> WORLD
    """
    Parse.doc_string().verify_all(lambda s: s.upper())

With type transforms:

from approvaltests.inline.parse import Parse

def test_add():
    """
    1, 2 -> 3
    5, 3 -> 8
    """
    Parse.doc_string().transform2(int, int).verify_all(lambda a, b: a + b)

With auto-approve:

Parse.doc_string(auto_approve=True).verify_all(lambda s: s.upper())

With Combinations

from approvaltests import verify_all_combinations_with_labeled_input, Options

def test_combinations():
    """
    (arg1: 1, arg2: 2) => 3
    (arg1: 1, arg2: 4) => 5
    (arg1: 3, arg2: 2) => 5
    (arg1: 3, arg2: 4) => 7
    """
    verify_all_combinations_with_labeled_input(
        lambda a, b: a + b,
        arg1=(1, 3),
        arg2=(2, 4),
        options=Options().inline(),
    )

Preserving Whitespace

Use marker for leading whitespace:

from approvaltests import verify, Options

def test_indented():
    """
    <<approvaltests:preserve-leading-whitespace>>
        4 spaces indent
            8 spaces indent
    """
    verify(get_indented_text(), options=Options().inline())

When to Use

Inline approvals work best for:

  • Short output (few lines)
  • Input/output mapping tests
  • Tests where expectation should be visible alongside code

File approvals work best for:

  • Long or complex output
  • Binary data
  • JSON/XML where syntax highlighting helps

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