๐Ÿ vcrpy is a must-have Python library for testing the code that heavily relies on a third-party API. When you run a test in the first time, records all network requests and responses in a YAML file. And when you run it in the next time, it will read the record from the file, make sure that the tested code sends the same requests, and return the recorded response.

There is a pytest plugin for vcrpy (pytest-recording) but I made my own ad hoc fixture because I can:

import pytest
from vcr import VCR

ROOT = Path(__file__).parent.parent

@pytest.fixture
def record_resp(request):
    path = ROOT / 'cassettes' / f'{request.node.name}.yaml'
    vcr = VCR(serializer='yaml')
    with vcr.use_cassette(str(path)):
        yield```