vcrpy
vcrpy copied to clipboard
Providing a Path to vcrpy doesn't save file
from pathlib import Path
my_path = Path.cwd() / 'cassette.json'
with vcr.use_cassette(my_file):
requests.get('http://httpbin.org/get')
No file is saved with the above scenario, however if you call str() on my_path, it will save the file.
If you don't support Path, I would at least accept an exception. Not that it fails silently, which is very unhelpful.
what is my_file? it's not defined anywhere.
if you want to use a path, supply it as a kwarg as in all the examples in the docs: https://vcrpy.readthedocs.io/en/latest/
This also drove me nuts for a bit.
I believe the my_file part in OP's example is just a typo. Should be:
from pathlib import Path
my_path = Path.cwd() / 'cassette.json'
with vcr.use_cassette(my_path):
requests.get('http://httpbin.org/get')
What works instead:
from pathlib import Path
my_path = Path.cwd() / 'cassette.json'
with vcr.use_cassette(str(my_path)):
requests.get('http://httpbin.org/get')
Could you point out where in the docs there's a kwarg that makes this work? From what I can tell it specifically wants a string, otherwise it assumes it's a decorator:
https://github.com/kevin1024/vcrpy/blob/e68aa846491db94837df9d49d50191a82adb44c1/vcr/config.py#L103
For example, this does not work for me:
from pathlib import Path
my_path = Path.cwd() / 'cassette.json'
with vcr.use_cassette(path=my_path):
requests.get('http://httpbin.org/get')
It doesn't fail, just VCR never kicks in.