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

@@ -60,3 +60,23 @@ def test_missing_matcher():
with pytest.raises(KeyError):
with my_vcr.use_cassette("test.yaml", match_on=["notawesome"]):
pass
def test_dont_record_on_exception(tmpdir):
my_vcr = vcr.VCR(record_on_exception=False)
@my_vcr.use_cassette(str(tmpdir.join('dontsave.yml')))
def some_test():
assert 'Not in content' in urlopen('http://httpbin.org/get')
with pytest.raises(AssertionError):
some_test()
assert not os.path.exists(str(tmpdir.join('dontsave.yml')))
# Make sure context decorator has the same behavior
with pytest.raises(AssertionError):
with my_vcr.use_cassette(str(tmpdir.join('dontsave2.yml'))):
assert 'Not in content' in urlopen('http://httpbin.org/get').read()
assert not os.path.exists(str(tmpdir.join('dontsave2.yml')))