{"id":5705,"library":"pytest-vcr","title":"pytest-vcr","description":"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.","status":"maintenance","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/ktosiek/pytest-vcr","tags":["pytest","vcr","testing","http","mocking","cassette","network"],"install":[{"cmd":"pip install pytest-vcr","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework integration.","package":"pytest"},{"reason":"Handles the actual recording and replaying of HTTP traffic.","package":"vcrpy"}],"imports":[{"note":"pytest-vcr is a pytest plugin and its main interaction is via markers, not direct imports of pytest_vcr.","symbol":"pytest.mark.vcr","correct":"import pytest\n\n@pytest.mark.vcr()"}],"quickstart":{"code":"import pytest\nimport requests # VCR.py integrates with requests\n\n@pytest.mark.vcr()\ndef test_example_http_request():\n    # The first run will record the request to 'cassettes/test_example_http_request.yaml'\n    # Subsequent runs will replay from the cassette.\n    response = requests.get('http://www.iana.org/domains/reserved')\n    assert response.status_code == 200\n    assert b'Example domains' in response.content\n","lang":"python","description":"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."},"warnings":[{"fix":"Uninstall `pytest-vcr` if using `pytest-recording`, or vice-versa: `pip uninstall pytest-vcr`","message":"pytest-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.","severity":"breaking","affected_versions":"All versions"},{"fix":"Replace usage of `vcr_cassette_path` with `vcr_cassette_dir` and `vcr_cassette_name` fixtures.","message":"The `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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Update CLI commands to use `--vcr-record` instead of `--vcr-record-mode`.","message":"The `--vcr-record-mode` command-line option was deprecated in version 1.0.0. Use `--vcr-record` instead.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Implement a `vcr_config` fixture: `@pytest.fixture(scope='module') def vcr_config(): return {'filter_headers': [('authorization', 'DUMMY')]}`","message":"Cassettes 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Run tests with `pytest --vcr-record=none` in CI/CD pipelines.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For services with time-sensitive authentication, consider using alternative mocking strategies or custom VCR.py matchers/filters if possible, or isolating these tests.","message":"pytest-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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}