DEV.co
Open-Source Testing · kiwicom

pytest-recording

pytest-recording is a pytest plugin that records and replays HTTP traffic during testing using VCR.py. It allows tests to run against pre-recorded cassettes, reducing dependency on external services and speeding up test execution.

Source: GitHub — github.com/kiwicom/pytest-recording
612
GitHub stars
49
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorykiwicom/pytest-recording
Ownerkiwicom
Primary languagePython
LicenseMIT — OSI-approved
Stars612
Forks49
Open issues40
Latest releasev0.13.4 (2025-05-08)
Last updated2026-06-18
Sourcehttps://github.com/kiwicom/pytest-recording

What pytest-recording is

A Python pytest plugin wrapper around VCR.py that provides decorators (@pytest.mark.vcr) for recording/replaying HTTP interactions, with support for multiple cassettes, network blocking, custom matchers, and configurable record modes (once, none, rewrite, all).

Quickstart

Get the pytest-recording source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/kiwicom/pytest-recording.gitcd pytest-recording# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

API Integration Testing

Record real API responses once, then replay them in CI/CD and local test runs. Eliminates flaky tests caused by external API changes and reduces test runtime.

Offline Test Execution

Run full test suites without network access by replaying cassettes. Ensures tests pass consistently in air-gapped environments and isolated CI runners.

Test Isolation & Determinism

Guarantee reproducible test behavior by capturing HTTP responses once. Prevent test failures from rate-limiting, downtime, or API response variability.

Implementation considerations

  • Cassette files must be committed to version control or regenerated in CI; decide on storage strategy and file naming conventions upfront.
  • Sensitive data (API keys, auth tokens, PII) must be filtered via vcr_config (filter_headers, filter_query_parameters) to prevent leaking secrets into cassettes.
  • Record mode defaults to 'none' (no network access); tests fail silently if cassettes are missing—require explicit --record-mode flag to regenerate.
  • Multiple cassettes can be combined via decorators; merging order and conflict resolution behavior should be documented per test suite.
  • Custom VCR matchers (via pytest_recording_configure hook) may be needed if default request matching (URL/method) is insufficient.

When to avoid it — and what to weigh

  • Need Real-Time API Behavior Testing — If tests must validate live API state changes (e.g., payment processing, real-time data feeds), cassettes will return stale recordings and mask real failures.
  • Testing Highly Dynamic or Protocol-Specific Services — VCR.py works with HTTP/HTTPS. Incompatible with WebSocket, gRPC, or binary protocols. Cassettes are brittle if request/response structure changes frequently.
  • Require Minimal Overhead in Test Setup — Cassette management adds complexity: maintaining cassette files, handling media encoding, managing sensitive data filtering. Adds file I/O on every test run.
  • Conflict with pytest-vcr — Plugin is explicitly incompatible with pytest-vcr. Teams already using pytest-vcr must migrate, which may require refactoring test decorators.

License & commercial use

MIT License. Permissive OSI-approved license allows unrestricted use, modification, and distribution in commercial and proprietary contexts, subject only to retention of copyright and license notice.

MIT License explicitly permits commercial use without restriction. No vendor lock-in, no commercial terms beyond attribution. Safe for production test infrastructure in proprietary codebases.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

Cassettes record full HTTP requests/responses; sensitive data (credentials, tokens, PII) must be explicitly filtered via filter_headers and filter_query_parameters to prevent accidental secrets in version control. Default behavior does NOT redact sensitive data automatically. Network blocking feature supports allowed_hosts allowlisting to prevent unintended outbound requests during test runs.

Alternatives to consider

pytest-httpserver / responses

Manually mock HTTP endpoints instead of recording. Provides more explicit control but requires handwritten response stubs; does not capture real API behavior.

unittest.mock + fixture data

Pure mocking without VCR. Lighter weight but brittle if API contracts change; does not encourage recording real behavior.

Live API tests + feature flags

Run against real APIs in staging with feature flags to isolate tests. Requires staging environment and network access; slower but captures live behavior.

Software development agency

Build on pytest-recording with DEV.co software developers

Replace flaky external API calls with deterministic cassettes. pytest-recording captures real behavior once, replays it forever. Faster CI, zero network dependency.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

pytest-recording FAQ

How do I prevent secrets (API keys) from being recorded in cassettes?
Use the vcr_config fixture with filter_headers and filter_query_parameters. Example: {"filter_headers": ["authorization"], "filter_query_parameters": ["api_key"]}. These are redacted in cassette files.
What happens if a cassette file is missing when I run tests?
Tests fail with a RuntimeError because the default record mode is 'none'. Regenerate cassettes by running pytest with --record-mode=once or --record-mode=all.
Can I use pytest-recording with pytest-vcr?
No, they are incompatible. You must uninstall pytest-vcr before using pytest-recording.
How do I ensure cassettes are reproducible across CI and local development?
Commit cassette YAML files to version control. Use --record-mode=none in tests to enforce replay-only. Regenerate cassettes in a dedicated CI step if needed (--record-mode=rewrite), then commit.

Custom software development services

From first prototype to production, DEV.co delivers software development services around tools like pytest-recording. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source testing and beyond.

Stabilize Your API Tests

Replace flaky external API calls with deterministic cassettes. pytest-recording captures real behavior once, replays it forever. Faster CI, zero network dependency.