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-vcrVerified import paths — ran on the pinned version, not inferred.
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.
Uninstall `pytest-vcr` if using `pytest-recording`, or vice-versa: `pip uninstall pytest-vcr`
Replace usage of `vcr_cassette_path` with `vcr_cassette_dir` and `vcr_cassette_name` fixtures.
Update CLI commands to use `--vcr-record` instead of `--vcr-record-mode`.
Implement a `vcr_config` fixture: `@pytest.fixture(scope='module') def vcr_config(): return {'filter_headers': [('authorization', 'DUMMY')]}`Run tests with `pytest --vcr-record=none` in CI/CD pipelines.
For services with time-sensitive authentication, consider using alternative mocking strategies or custom VCR.py matchers/filters if possible, or isolating these tests.
Verify compatibility with your specific Python and pytest versions. Consider `pytest-recording` for more active maintenance and broader compatibility with modern Python/pytest ecosystems.