Skip to content

Commit

Permalink
Merge pull request #6 from obspy/playback_only
Browse files Browse the repository at this point in the history
add VCRSystem option to force-deactivate recording and only do playback
  • Loading branch information
barsch authored Apr 1, 2017
2 parents eead198 + 0fc9e89 commit 9ba7294
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion vcr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class VCRSystem(object):
debug = False
disabled = False
overwrite = False
playback_only = False
recv_timeout = 5
recv_endmarkers = []
recv_size = None
Expand All @@ -95,6 +96,7 @@ def reset(cls):
cls.debug = False
cls.disabled = False
cls.overwrite = False
cls.playback_only = False
cls.recv_timeout = 5
cls.recv_endmarkers = []
cls.recv_size = None
Expand Down Expand Up @@ -463,7 +465,9 @@ def _vcr_inner(*args, **kwargs):
tape = os.path.join(path, '%s.%s.vcr' % (file_name, func_name))

# check for tape file and determine mode
if not os.path.isfile(tape) or overwrite or VCRSystem.overwrite:
if not VCRSystem.playback_only and (
not os.path.isfile(tape) or
overwrite or VCRSystem.overwrite):
# remove existing tape
try:
os.remove(tape)
Expand Down Expand Up @@ -495,6 +499,10 @@ def _vcr_inner(*args, **kwargs):
if VCRSystem.debug:
print('\nVCR PLAYBACK (%s) ...' % (func_name))
VCRSystem.status = VCR_PLAYBACK
# if playback is requested and tape is missing: raise!
if not os.path.exists(tape):
msg = 'Missing VCR tape file for playback: {}'.format(tape)
raise Exception(msg)
# load playlist
with open(tape, 'rb') as fh:
VCRSystem.playlist = pickle.load(fh)
Expand Down

0 comments on commit 9ba7294

Please sign in to comment.