Skip to content

Extract JSON responses from cassettes - #541

Merged
martin-majlis merged 2 commits into
masterfrom
cassettes-extract-bodies-from-responses
Apr 6, 2026
Merged

martin-majlis merged 2 commits into
masterfrom
cassettes-extract-bodies-from-responses

Conversation

@martin-majlis

Copy link
Copy Markdown
Owner

VCR JSON Extractor

Summary

Add utility to extract clean JSON responses from VCR cassette files, eliminating escaped JSON complexity.

Features

  • Clean JSON Output: Extracts unescaped, pretty-printed JSON from VCR cassettes
  • Multiple Interactions: Handles cassettes with multiple HTTP requests/responses
  • CLI Interface: Command-line tool with flexible options
  • Makefile Integration: make extract-vcr-json target for easy usage
  • Error Handling: Graceful processing of malformed files

Usage

# Default extraction (tests/cassettes → tests/cassettes-json)
make extract-vcr-json

# Custom options
python extract_vcr_json.py --input-dir my-cassettes --output-dir json-output --verbose

Output Structure

tests/cassettes-json/
├── TestVcrAsyncPageExistence.test_exists_true_0.json
├── TestVcrWikiCoordinates.test_default_0.json
└── ... (349 JSON files extracted from 247 cassettes)

Benefits

  • No More Escaped JSON: Work with clean, readable JSON responses
  • Easy Analysis: Simple inspection of API responses during development
  • Test Infrastructure: Integrates seamlessly with existing VCR tests
  • Flat Structure: Related files grouped together for easy browsing

Files Added

  • extract_vcr_json.py - Main extraction script
  • VCR_JSON_EXTRACTOR.md - Comprehensive documentation
  • Makefile - New extract-vcr-json target
  • tests/cassettes-json/ - 349 extracted JSON response files

Technical Details

  • Processes VCR cassette interactions[].response.body.string fields
  • Handles multiple HTTP interactions per cassette with index-based naming
  • Pretty-prints JSON with 2-space indentation
  • Comprehensive error handling and verbose output options
  • Maintains relationship between test names and responses

Verification

✅ Successfully extracted 349 JSON responses from 247 cassette files
✅ All pre-commit hooks pass
✅ Documentation complete with examples
✅ Makefile integration working

@codecov

codecov Bot commented Apr 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.36%. Comparing base (182aeaa) to head (77d99c7).
⚠️ Report is 83 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #541   +/-   ##
=======================================
  Coverage   94.36%   94.36%           
=======================================
  Files          72       72           
  Lines        3339     3339           
=======================================
  Hits         3151     3151           
  Misses        188      188           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martin-majlis
martin-majlis merged commit 49811b3 into master Apr 6, 2026
42 of 43 checks passed
@martin-majlis
martin-majlis deleted the cassettes-extract-bodies-from-responses branch April 6, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant