Registry / testing / pytest-vcr

pytest-vcr

JSON →
library1.0.2pypypi✓ verified 24d ago

pytest-vcr is a pytest plugin that simplifies testing HTTP interactions by integrating with VCR.py. It records HTTP requests and responses to YAML 'cassettes' during the first test run, then replays them on subsequent runs, making tests faster, more deterministic, and runnable offline. The current version is 1.0.2, released in April 2019, indicating an infrequent release cadence.

pip install pytest-vcr
INSTALL
IMPORT
SIG · PYTEST-VCR
P
pytest-vcr
testingpythonv1.0.2
Install
3.8s avg
Import
912ms
Disk
35MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.948s · 34.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.8s · import 0.876s · 36MB
35MB installed
● package 35MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

VCR
from pytest_vcr import VCR
import pytest
vcr
from pytest_vcr import vcr
import pytest
pytest_addoption
from pytest_vcr import pytest_addoption
import pytest

Decorate your test function with `@pytest.mark.vcr()`. On the first run, it records HTTP traffic to a YAML cassette file (e.g., `cassettes/test_example_http_request.yaml`). Subsequent runs will replay from this cassette. Cassette files should be committed to version control.

import pytest import requests # VCR.py integrates with requests @pytest.mark.vcr() def test_example_http_request(): # The first run will record the request to 'cassettes/test_example_http_request.yaml' # Subsequent runs will replay from the cassette. response = requests.get('http://www.iana.org/domains/reserved') assert response.status_code == 200 assert b'Example domains' in response.content
Debug
Known issues
breakingpytest-vcr is incompatible with `pytest-recording`, an alternative VCR.py plugin for pytest. If both are installed, unexpected behavior or errors may occur. It is recommended to choose one plugin and uninstall the other.
fix
Uninstall `pytest-vcr` if using `pytest-recording`, or vice-versa: `pip uninstall pytest-vcr`
affects: All versions
breakingThe `vcr_cassette_path` fixture was removed in version 1.0.0. To customize cassette paths, use the `vcr_cassette_dir` and `vcr_cassette_name` fixtures instead.
fix
Replace usage of `vcr_cassette_path` with `vcr_cassette_dir` and `vcr_cassette_name` fixtures.
affects: >=1.0.0
deprecatedThe `--vcr-record-mode` command-line option was deprecated in version 1.0.0. Use `--vcr-record` instead.
fix
Update CLI commands to use `--vcr-record` instead of `--vcr-record-mode`.
affects: >=1.0.0
gotchaCassettes can record sensitive information (e.g., API keys, authorization headers). To prevent this, use the `vcr_config` fixture in your `conftest.py` with `filter_headers` to redact sensitive data.
fix
Implement a `vcr_config` fixture: `@pytest.fixture(scope='module') def vcr_config(): return {'filter_headers': [('authorization', 'DUMMY')]}`
affects: All versions
gotchaWhen running tests in a Continuous Integration (CI) environment, it is recommended to use the `--vcr-record=none` option. This ensures that no new network requests are made, preventing accidental re-recording and verifying all necessary cassettes are committed.
fix
Run tests with `pytest --vcr-record=none` in CI/CD pipelines.
affects: All versions
gotchapytest-vcr may not work reliably with services that use time-sensitive authentication (e.g., certain Google DataStore authentication methods) as recorded requests might become invalid over time, leading to cassette replay failures.
fix
For services with time-sensitive authentication, consider using alternative mocking strategies or custom VCR.py matchers/filters if possible, or isolating these tests.
affects: All versions
gotchaThe library's last release was in April 2019. It may not be fully compatible with newer Python versions (e.g., Python 3.8+ as its core dependency `VCR.py` has dropped support for older Python versions like 3.7) or recent major versions of `pytest`.
fix
Verify compatibility with your specific Python and pytest versions. Consider `pytest-recording` for more active maintenance and broader compatibility with modern Python/pytest ecosystems.
affects: >=1.0.0
Upgrade
Version history
1.0.2latest on PyPI · released Apr 26, 2019
Audit
Dependencies
pytestrequiredCore testing framework integration.
vcrpyrequiredHandles the actual recording and replaying of HTTP traffic.
Agent activity
15 hits · last 30 days
node
12
Resources
pytest-vcr — pip install pytest-vcr · libregistry