mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 17:15:35 +00:00
Add global toggle to use_cassette.
This commit is contained in:
@@ -14,15 +14,33 @@ from .matchers import requests_match, uri, method
|
||||
from .errors import UnhandledHTTPRequestError
|
||||
|
||||
|
||||
class NullContextDecorator(object):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def __enter__(self, *args):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
pass
|
||||
|
||||
def __call__(self, function):
|
||||
return function
|
||||
|
||||
|
||||
class use_cassette(object):
|
||||
|
||||
_enabled = True
|
||||
|
||||
def __init__(self, cls, *args, **kwargs):
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self.cls = cls
|
||||
|
||||
def __enter__(self):
|
||||
self._cassette = self.cls.load(*self.args, **self.kwargs)
|
||||
self._cassette = self.cls.load(*self.args, **self.kwargs) if self._enabled \
|
||||
else NullContextDecorator()
|
||||
return self._cassette.__enter__()
|
||||
|
||||
def __exit__(self, *args):
|
||||
|
||||
Reference in New Issue
Block a user