Currently I've only tested this with urllib2, urllib3, and requests. It's known to *NOT WORK* with urllib.
-##How to use it
+##Usage
```python
import vcr
import urllib2
accurate (the response will contain the same headers and body you get from a
real request).
+You can also use VCR.py as a decorator. The same request above would look like this:
+
+```
+@vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml'):
+def test_iana():
+ response = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
+ assert 'Example domains' in response
+```
+
+All of the parameters and configuration works the same for the decorator version.
+
## Configuration
If you don't like VCR's defaults, you can set options by instantiating a
'vcr.compat': 'vcr/compat',
'vcr.persisters': 'vcr/persisters',
},
- install_requires=['PyYAML'],
+ install_requires=['PyYAML','contextdecorator'],
license='MIT',
tests_require=['pytest','mock'],
cmdclass={'test': PyTest},
urllib2.urlopen('http://httpbin.org/')
assert len(cass) == 2
assert cass.play_count == 0
+
+def test_decorator(scheme, tmpdir):
+ '''Test the decorator version of VCR.py'''
+ url = scheme + '://httpbin.org/'
+
+ @vcr.use_cassette(str(tmpdir.join('atts.yaml')))
+ def inner1():
+ return urllib2.urlopen(url).getcode()
+
+ @vcr.use_cassette(str(tmpdir.join('atts.yaml')))
+ def inner2():
+ return urllib2.urlopen(url).getcode()
+
+ assert inner1() == inner2()
from .compat.counter import Counter
from .compat.ordereddict import OrderedDict
+from contextdecorator import ContextDecorator
+
# Internal imports
from .patch import install, reset
from .persist import load_cassette, save_cassette
from .matchers import requests_match, url, method
-class Cassette(object):
+class Cassette(ContextDecorator):
'''A container for recorded requests and responses'''
@classmethod