context manager not working, cassette not accessible
valentijnscholten opened this issue · comments
Hi,
I tried using vcr to record http traffic during my unittests. It works fine, but I can't seem to be able to access the cassette to run assertions on it.
my_vcr = vcr.VCR(
record_mode='all', path_transformer=VCR.ensure_suffix('.yaml'),
cassette_library_dir='dojo/unittests/vcr/jira/',
)
@my_vcr.use_cassette()
def test_import_no_push_to_jira(self):
.... how to access cassette.... my_vcr.cassette doesn't exist. my_vcr.use_casette is a function... my_vcr.is_cassette() doesn't work
I tried using the context manager, but this results in a KeyError on path
:
def test_import_no_push_to_jira(self):
with my_vcr.use_cassette() as cassette:
...
cassette.assertTrue(cassette.all_played)
Traceback (most recent call last):
File "/app/dojo/unittests/test_jira_config_and_pushing_api.py", line 72, in test_import_no_push_to_jira
with my_vcr.use_cassette() as cassette:
File "/usr/local/lib/python3.6/site-packages/vcr/cassette.py", line 86, in __enter__
cassette_kwargs["path"] = transformer(cassette_kwargs["path"])
KeyError: 'path'
Same happens when I configure inline:
def test_import_no_push_to_jira(self):
with vcr.use_cassette(record_mode='all', path_transformer=VCR.ensure_suffix('.yaml'),
filter_headers=['Authorization', 'X-Atlassian-Token'],
cassette_library_dir='dojo/unittests/vcr/jira/',
before_record_request=before_record_request,
before_record_response=before_record_response) as cassette:
cassette.assertTrue(cassette.all_played)
maybe it's my python skills, but I think at least one of these should work.