'vcr.compat': 'vcr/compat',
'vcr.persisters': 'vcr/persisters',
},
- install_requires=['PyYAML', 'contextdecorator', 'six'],
+ install_requires=['PyYAML', 'six'],
license='MIT',
tests_require=['pytest', 'mock', 'pytest-localserver'],
cmdclass={'test': PyTest},
+from six.moves import http_client as httplib
+
import pytest
import yaml
import mock
+
from vcr.cassette import Cassette
from vcr.errors import UnhandledHTTPRequestError
@mock.patch('vcr.cassette.Cassette.can_play_response_for', return_value=True)
@mock.patch('vcr.stubs.VCRHTTPResponse')
def test_function_decorated_with_use_cassette_can_be_invoked_multiple_times(*args):
- from six.moves import http_client as httplib
- @Cassette.use_cassette('test')
+ @Cassette.use('test')
def decorated_function():
conn = httplib.HTTPConnection("www.python.org")
conn.request("GET", "/index.html")
--- /dev/null
+import mock
+
+from vcr import VCR
+
+
+
+def test_vcr_use_cassette():
+ filter_headers = mock.Mock()
+ test_vcr = VCR(filter_headers=filter_headers)
+ with mock.patch('vcr.config.Cassette') as mock_cassette_class:
+ @test_vcr.use_cassette('test')
+ def function():
+ pass
+ mock_cassette_class.call_count == 0
+ function()
+ assert mock_cassette_class.use.call_args[1]['filter_headers'] is filter_headers
from .errors import UnhandledHTTPRequestError
-class use_cassette(object):
+class CassetteContextDecorator(object):
+ """Context manager/decorator that handles installing the cassette and
+ removing cassettes.
+
+ This class defers the creation of a new cassette instance until the point at
+ which it is installed by context manager or decorator. The fact that a new
+ cassette is used with each application prevents the state of any cassette
+ from interfering with another.
+ """
def __init__(self, cls, *args, **kwargs):
self.args = args
return new_cassette
@classmethod
- def use_cassette(cls, *args, **kwargs):
- return use_cassette(cls, *args, **kwargs)
+ def use(cls, *args, **kwargs):
+ return CassetteContextDecorator(cls, *args, **kwargs)
+
+ use_cassette = use
def __init__(self,
path,
),
}
- return Cassette.use_cassette(path, **merged_config)
+ return Cassette.use(path, **merged_config)
def register_serializer(self, name, serializer):
self.serializers[name] = serializer