Cassette expiry¶
Cassettes rot. The API adds a field, renames another, and your tests keep passing against a response from six months ago.
Set max_age to catch that:
max_age accepts durations like "24h", "7d", "4w". When the cassette is older than that, on_expiry decides what happens:
| Action | Behavior |
|---|---|
warn |
Emit a CassetteExpiredWarning (the default) |
fail |
Raise CassetteExpiredError |
rerecord |
Delete the cassette and record it again |
With pytest¶
Configure it for a module through vcr_config:
Or per test, through the marker:
Tip
A good setup: on_expiry="warn" in CI so nothing breaks unexpectedly, and an occasional local run with --record-mode=all to refresh everything.