mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-10 09:35:34 +00:00
Revert "Add global toggle to use_cassette."
This reverts commit 366e2b75bb.
Conflicts:
tests/unit/test_cassettes.py
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
from .config import VCR
|
||||
from . import cassette
|
||||
|
||||
# Set default logging handler to avoid "No handler found" warnings.
|
||||
try: # Python 2.7+
|
||||
@@ -10,9 +9,6 @@ except ImportError:
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
def global_toggle(enabled=True):
|
||||
cassette.use_cassette._enabled = enabled
|
||||
|
||||
|
||||
logging.getLogger(__name__).addHandler(NullHandler())
|
||||
|
||||
|
||||
@@ -14,33 +14,15 @@ 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) if self._enabled \
|
||||
else NullContextDecorator()
|
||||
self._cassette = self.cls.load(*self.args, **self.kwargs)
|
||||
return self._cassette.__enter__()
|
||||
|
||||
def __exit__(self, *args):
|
||||
|
||||
Reference in New Issue
Block a user