]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Python version agnostic way of getting the next item in the generator.
authorIvan Malison <IvanMalison@gmail.com>
Thu, 18 Sep 2014 12:59:03 +0000 (05:59 -0700)
committerIvan Malison <IvanMalison@gmail.com>
Thu, 18 Sep 2014 12:59:03 +0000 (05:59 -0700)
vcr/cassette.py

index 8949c197d9b88dea5d165560885a457cddcaff9d..e5e58adb14aa774f11621b61c0335c339bf700c2 100644 (file)
@@ -38,20 +38,18 @@ class CassetteContextDecorator(object):
         with contextlib2.ExitStack() as exit_stack:
             for patcher in build_patchers(cassette):
                 exit_stack.enter_context(patcher)
-            yield
+            yield cassette
              # TODO(@IvanMalison): Hmmm. it kind of feels like this should be somewhere else.
             cassette._save()
 
     def __enter__(self):
         assert self.__finish is None
         path, kwargs = self._args_getter()
-        cassette = self.cls.load(path, **kwargs)
-        self.__finish = self._patch_generator(cassette)
-        self.__finish.__next__()
-        return cassette
+        self.__finish = self._patch_generator(self.cls.load(path, **kwargs))
+        return next(self.__finish)
 
     def __exit__(self, *args):
-        [_ for _ in self.__finish] # this exits the context created by the call to _patch_generator.
+        next(self.__finish, None)
         self.__finish = None
 
     def __call__(self, function):