1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 09:13:23 +00:00

Add record_on_exception flag.

Defaults to True, which maintains historical behavior.

Fixes #205.
This commit is contained in:
Dan Passaro
2015-12-11 13:39:15 -05:00
committed by Jair Henrique
parent 423ccaa40b
commit 995020bf06
3 changed files with 34 additions and 3 deletions

View File

@@ -45,7 +45,9 @@ class CassetteContextDecorator:
this class as a context manager in ``__exit__``.
"""
_non_cassette_arguments = ("path_transformer", "func_path_generator")
_non_cassette_arguments = (
"path_transformer", "func_path_generator", "record_on_exception",
)
@classmethod
def from_args(cls, cassette_class, **kwargs):
@@ -87,8 +89,13 @@ class CassetteContextDecorator:
self.__finish = self._patch_generator(self.cls.load(**cassette_kwargs))
return next(self.__finish)
def __exit__(self, *args):
next(self.__finish, None)
def __exit__(self, *exc_info):
exception_was_raised = any(exc_info)
record_on_exception = self._args_getter().get(
'record_on_exception', True
)
if record_on_exception or not exception_was_raised:
next(self.__finish, None)
self.__finish = None
@wrapt.decorator