pytest-vcr

1.0.2 · maintenance · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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

view raw JSON →