Skip to content

Record Modes

Record modes control when grpcvcr records new interactions versus playing back existing ones.

Overview

from grpcvcr import RecordMode

# Always record (useful for updating cassettes)
print(RecordMode.ALL)

# Never record (playback only, raises if no match)
print(RecordMode.NONE)

# Record only new interactions (default)
print(RecordMode.NEW_EPISODES)

# Record once if cassette empty
print(RecordMode.ONCE)

Mode Comparison

Mode Existing Match No Match
NONE Playback Raises error
NEW_EPISODES Playback Record
ALL Record Record
ONCE Playback Record (if cassette empty)

API Reference

Bases: Enum

Controls how the cassette handles recording and playback.

Example
from grpcvcr import Cassette, RecordMode

# Playback only - fails if interaction not found
cassette = Cassette("test.yaml", record_mode=RecordMode.NONE)

# Record new interactions, replay existing ones (default)
cassette = Cassette("test.yaml", record_mode=RecordMode.NEW_EPISODES)

# Always record, overwriting existing
cassette = Cassette("test.yaml", record_mode=RecordMode.ALL)

# Record once, then playback only
cassette = Cassette("test.yaml", record_mode=RecordMode.ONCE)

NONE class-attribute instance-attribute

NONE = 'none'

Playback only. Raises error if no matching interaction found. Use in CI to ensure all interactions are pre-recorded.

NEW_EPISODES class-attribute instance-attribute

NEW_EPISODES = 'new_episodes'

Play back existing interactions, record new ones. Default mode - good for iterative test development.

ALL class-attribute instance-attribute

ALL = 'all'

Always record, overwriting existing interactions. Use to refresh cassettes after API changes.

ONCE class-attribute instance-attribute

ONCE = 'once'

Record if cassette doesn't exist, then playback only. Good for one-time setup of test fixtures.