]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Fix use_cassette decorator in python 2 by using wrapt.decorator. Add wrapt as dependency.
authorIvan Malison <IvanMalison@gmail.com>
Mon, 22 Sep 2014 23:40:09 +0000 (16:40 -0700)
committerIvan Malison <IvanMalison@gmail.com>
Mon, 22 Sep 2014 23:40:09 +0000 (16:40 -0700)
setup.py
tests/unit/test_vcr.py
vcr/cassette.py

index df313706f9e67416b7b0be5fecd67da825959570..329dfeb4475f2421515abb54be4c63b287273f1a 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -41,7 +41,7 @@ setup(
         'vcr.compat': 'vcr/compat',
         'vcr.persisters': 'vcr/persisters',
         },
-    install_requires=['PyYAML', 'mock', 'six', 'contextlib2'],
+    install_requires=['PyYAML', 'mock', 'six', 'contextlib2', 'wrapt'],
     license='MIT',
     tests_require=['pytest', 'mock', 'pytest-localserver'],
     cmdclass={'test': PyTest},
index c1dc6f039f9cdce612c714db78c1ad3f76c0cc1a..a2143aa92690e7a9e1ebd5520f238667c1065d6b 100644 (file)
@@ -1,6 +1,7 @@
 import mock
+import pytest
 
-from vcr import VCR
+from vcr import VCR, use_cassette
 
 
 def test_vcr_use_cassette():
@@ -26,3 +27,21 @@ def test_vcr_use_cassette():
 
     with test_vcr.use_cassette('test', filter_headers=new_filter_headers) as cassette:
         assert cassette._filter_headers == new_filter_headers
+
+
+@pytest.fixture
+def random_fixture():
+    return 1
+
+
+@use_cassette('test')
+def test_fixtures_with_use_cassette(random_fixture):
+    # Applying a decorator to a test function that requests features can cause
+    # problems if the decorator does not preserve the signature of the original
+    # test function.
+
+    # This test ensures that use_cassette preserves the signature of the original
+    # test function, and thus that use_cassette is compatible with py.test
+    # fixtures. It is admittedly a bit strange because the test would never even
+    # run if the relevant feature were broken.
+    pass
index d5c33b8c050c1f25bb13a8353f620543e5f10050..bc52340bc1518015a2a9dc5d452df47ef542d035 100644 (file)
@@ -2,6 +2,7 @@
 import logging
 
 import contextlib2
+import wrapt
 try:
     from collections import Counter
 except ImportError:
@@ -19,7 +20,7 @@ from .errors import UnhandledHTTPRequestError
 log = logging.getLogger(__name__)
 
 
-class CassetteContextDecorator(contextlib2.ContextDecorator):
+class CassetteContextDecorator(object):
     """Context manager/decorator that handles installing the cassette and
     removing cassettes.
 
@@ -58,6 +59,11 @@ class CassetteContextDecorator(contextlib2.ContextDecorator):
         next(self.__finish, None)
         self.__finish = None
 
+    @wrapt.decorator
+    def __call__(self, function, instance, args, kwargs):
+        with self:
+            return function(*args, **kwargs)
+
 
 class Cassette(object):
     '''A container for recorded requests and responses'''