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.

referencespythonsetup.md

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

Python ApprovalTests Setup

Contents

Installation

pip install approvaltests

For pytest reporter selection:

pip install pytest-approvaltests

Optional dependencies:

pip install pyperclip        # ClipboardReporter
pip install beautifulsoup4   # verify_html
pip install allpairspy       # verify_best_covering_pairs
pip install testfixtures mock  # verify_logging

pytest Integration

from approvaltests import verify

def test_simple():
    result = "Hello ApprovalTests"
    verify(result)

Run with reporter:

pytest --approvaltests-use-reporter='PythonNative'

unittest Integration

import unittest
from approvaltests import verify

class MyTest(unittest.TestCase):
    def test_simple(self):
        verify("Hello ApprovalTests")

if __name__ == "__main__":
    unittest.main()

Reporters

Set a reporter per-test or globally.

Per-test

from approvaltests import verify, Options
from approvaltests.reporters import PythonNativeReporter

verify("Hello", options=Options().with_reporter(PythonNativeReporter()))

Global default

from approvaltests import set_default_reporter
from approvaltests.reporters import PythonNativeReporter

set_default_reporter(PythonNativeReporter())

Or via pytest fixture in conftest.py:

import pytest
from approvaltests import set_default_reporter
from approvaltests.reporters import PythonNativeReporter

@pytest.fixture(scope="session", autouse=True)
def configure_approvaltests():
    set_default_reporter(PythonNativeReporter())

For diff tools, custom reporters, and chaining: see reporters.md

Configuration

Approval File Subdirectory

Place approvaltests_config.json in test directory:

{
  "subdirectory": "approved_files"
}

All .approved and .received files go to tests/approved_files/.

Custom File Extensions

from approvaltests import verify, Options

verify(html_content, options=Options().for_file.with_extension(".html"))
verify(xml_content, options=Options().for_file.with_extension(".xml"))

Git Setup

Add to .gitignore:

*.received.*

Commit all .approved.* files.

For consistent line endings across platforms, add to .gitattributes:

*.approved.* text eol=lf

CI Troubleshooting

Test passes locally, fails in CI

Common causes:

Line endings - Windows vs Unix

Solution: Add .gitattributes rule above

Timezones - Date output differs by environment

Solution: Use scrubbers for timestamps (see scrubbers.md)

Locale/encoding - Character encoding differs

Solution: Set PYTHONIOENCODING=utf-8 in CI

Missing scrubber - Environment-specific data not scrubbed

Common culprits: file paths, hostnames, process IDs, timestamps

PyCharm strips trailing whitespace

PyCharm auto-removes trailing whitespace on save, causing approval files to mismatch.

Fix: File → Settings → Editor → General → On Save → uncheck "Remove trailing spaces"

Comparing files manually

git diff --no-index test.approved.txt test.received.txt

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