From 0fc9e89566056c5d6fd8f80c5353d361a6d7d2d0 Mon Sep 17 00:00:00 2001 From: Tobias Megies Date: Sat, 1 Apr 2017 11:47:18 +0200 Subject: [PATCH] add VCRSystem option to force deactivate recording and only do playback --- vcr/core.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vcr/core.py b/vcr/core.py index cd20025..ec74019 100644 --- a/vcr/core.py +++ b/vcr/core.py @@ -83,6 +83,7 @@ class VCRSystem(object): debug = False disabled = False overwrite = False + playback_only = False recv_timeout = 5 recv_endmarkers = [] recv_size = None @@ -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 @@ -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) @@ -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)