pytest-recording
Record and replay HTTP interactions in Python tests
Testing external APIs is unreliable and slow due to network dependencies and rate limits. pytest-recording captures HTTP interactions as reusable YAML cassettes for fast, deterministic tests. Use this skill to mock API calls, filter sensitive credentials, and debug VCR configuration issues.
تنزيل ZIP المهارة
رفع في Claude
اذهب إلى Settings → Capabilities → Skills → Upload skill
فعّل وابدأ الاستخدام
اختبرها
استخدام "pytest-recording". Create a VCR test for an API that requires Bearer token authentication
النتيجة المتوقعة:
- Add @pytest.mark.vcr() decorator to your test function
- Create vcr_config fixture to filter authorization header
- Run test with --vcr-record=once to create initial cassette
- Verify cassette does not contain your token by checking the YAML file
- Future runs will use recorded response without making live API calls
استخدام "pytest-recording". How do I update cassettes when the API changes?
النتيجة المتوقعة:
- Option 1: Delete specific cassette files and re-run tests with --vcr-record=once
- Option 2: Use --vcr-record=rewrite to refresh all cassettes at once
- Option 3: Use --vcr-record=new_episodes to add new responses while keeping existing ones
- Review updated cassettes to ensure they contain expected response data
التدقيق الأمني
آمنThis is a documentation-only skill for pytest-recording (VCR.py), a widely-used Python testing library. All 67 static findings are false positives. The 'external commands' are example pytest/shell commands in documentation code blocks, 'hardcoded IP addresses' are localhost examples for configuring VCR ignore_hosts, and 'API keys' are demonstrating how to filter sensitive authentication headers from recordings. The skill teaches security best practices for protecting credentials, not exploiting them.
عوامل الخطر
⚙️ الأوامر الخارجية (1)
🌐 الوصول إلى الشبكة (1)
🔑 متغيرات البيئة (1)
درجة الجودة
ماذا يمكنك بناءه
Mock external API calls
Replace live API calls with recorded responses for reliable, fast test execution without rate limits or network dependencies.
Create deterministic tests
Ensure tests produce consistent results by replaying exact HTTP responses, eliminating flaky tests from API changes.
Secure CI/CD testing
Run tests in CI/CD pipelines without exposing API credentials by filtering sensitive data from recorded cassettes.
جرّب هذه الموجهات
Convert this test to use pytest-recording: [paste test code]. Show me the decorator and needed imports.
Create a vcr_config fixture that filters authorization headers and API keys for OpenAI and Anthropic APIs.
My test cannot find the cassette file. Walk me through debugging steps including file paths and recording modes.
Show me how to configure VCR to match requests by method and path only, and sanitize response headers before recording.
أفضل الممارسات
- Always filter authentication headers and API keys before recording cassettes
- Use descriptive test names as they become cassette file names automatically
- Review cassette files in pull requests to ensure no secrets are committed
- Delete and re-record cassettes periodically to catch API changes early
تجنب
- Recording cassettes with real API credentials without filtering sensitive data
- Committing large cassette files with unnecessary HTTP interactions
- Using --vcr-record=all in CI/CD which overwrites working cassettes
- Ignoring cassette merge conflicts instead of re-recording properly