Agent Skillspydantic/pydantic-ai › testing-skill

testing-skill

GitHub

提供 Pytest VCR 工作流,支持录制、重写和验证 HTTP 测试磁带,调试磁带内容并解析 YAML 请求响应体。

.claude/skills/testing-skill/SKILL.md pydantic/pydantic-ai

Trigger Scenarios

运行带 --record-mode 参数的测试以录制或更新 VCR 磁带 验证磁带回放是否正确 检查或解析 VCR 磁带中的 HTTP 请求和响应数据

Install

npx skills add pydantic/pydantic-ai --skill testing-skill -g -y
More Options

Non-standard path

npx skills add https://github.com/pydantic/pydantic-ai/tree/main/.claude/skills/testing-skill -g -y

Use without installing

npx skills use pydantic/pydantic-ai@testing-skill

指定 Agent (Claude Code)

npx skills add pydantic/pydantic-ai --skill testing-skill -a claude-code -g -y

安装 repo 全部 skill

npx skills add pydantic/pydantic-ai --all -g -y

预览 repo 内 skill

npx skills add pydantic/pydantic-ai --list

SKILL.md

Frontmatter
{
    "name": "testing-skill",
    "description": "Record, rewrite, and debug VCR cassettes for HTTP recordings. Use when running tests with --record-mode, verifying cassette playback, or inspecting request\/response bodies in YAML cassettes.",
    "allowed-tools": "Bash(uv run pytest *), Bash(uv run python .claude\/skills\/testing-skill\/parse_cassette.py *), Bash(source .env && uv run pytest *), Bash(git diff *)"
}

Pytest VCR Workflow

Use this skill when recording or re-recording VCR cassettes for tests, or when debugging cassette contents.

Prerequisites

  • Verify .env exists: test -f .env && echo 'ok' || echo 'missing'
  • Missing API keys will cause clear test errors at runtime

Important flags

  • --record-mode=rewrite : Record cassettes (works for both new and existing)
  • --lf : Run only the last failed tests
  • -vv : Verbose output
  • --tb=line : Short traceback output
  • -k="" : Run tests matching the given substring expression

Recording Cassettes

Step 1: Record cassettes

source .env && uv run pytest path/to/test.py::test_function_name -v --tb=line --record-mode=rewrite

Multiple tests can be specified:

source .env && uv run pytest path/to/test.py::test_one path/to/test.py::test_two -v --tb=line --record-mode=rewrite

Step 2: Verify recordings

Run the same tests WITHOUT --record-mode to verify cassettes play back correctly:

source .env && uv run pytest path/to/test.py::test_function_name -vv --tb=line

Step 3: Review snapshots

If tests use snapshot() assertions:

  • The test run in Step 2 auto-fills snapshot content
  • Review the generated snapshot files to ensure they match expected output
  • You only review - don't manually write snapshot contents
  • Snapshots capture what the test actually produced, additional to explicit assertions

Parsing Cassettes

Parse VCR cassette YAML files to inspect request/response bodies without dealing with raw YAML.

Usage

uv run python .claude/skills/testing-skill/parse_cassette.py <cassette_path> [--interaction N]

Examples

# Parse all interactions in a cassette
uv run python .claude/skills/testing-skill/parse_cassette.py tests/models/cassettes/test_foo/test_bar.yaml

# Parse only interaction 1 (0-indexed)
uv run python .claude/skills/testing-skill/parse_cassette.py tests/models/cassettes/test_foo/test_bar.yaml --interaction 1

Output

For each interaction, shows:

  • Request: method, URI, parsed body (truncated base64)
  • Response: status code, parsed body (truncated base64)

Base64 strings longer than 100 chars are truncated for readability.

Full Workflow Example

# 1. Record cassette
source .env && uv run pytest tests/models/test_openai.py::test_chat_completion -v --tb=line --record-mode=rewrite

# 2. Verify playback and fill snapshots
source .env && uv run pytest tests/models/test_openai.py::test_chat_completion -vv --tb=line

# 3. Review test code diffs (excludes cassettes)
git diff tests/ -- ':!**/cassettes/**'

# 4. List new/changed cassettes (name only - use parse_cassette.py to inspect)
git diff --name-only tests/ -- '**/cassettes/**'

# 5. Inspect cassette contents if needed
uv run python .claude/skills/testing-skill/parse_cassette.py tests/models/cassettes/test_openai/test_chat_completion.yaml

Version History

  • 20cdf45 Current 2026-07-25 05:33

Same Skill Collection

.agents/skills/add-new-model/SKILL.md
.agents/skills/adding-a-provider-api-feature/SKILL.md
.agents/skills/complete-partial-pr/SKILL.md
.agents/skills/i-have-adhd/SKILL.md
.agents/skills/pushing-commits-to-the-repo/SKILL.md
.claude/skills/address-feedback/SKILL.md
.claude/skills/pre-push-review/SKILL.md
pydantic_ai_slim/pydantic_ai/.agents/skills/building-pydantic-ai-agents/SKILL.md
.agents/skills/poweruser-feature-audit/SKILL.md

Metadata

Files
0
Version
43f982f
Hash
4f0663ca
Indexed
2026-07-25 05:33

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-21 03:10
浙ICP备14020137号-1 $Гость$