vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

Providing a Path to vcrpy doesn't save file

Open jonathan-s opened this issue 5 years ago • 2 comments
trafficstars

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.

jonathan-s avatar Oct 22 '20 15:10 jonathan-s

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/

valentijnscholten avatar Nov 14 '20 21:11 valentijnscholten

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.

austinbutler avatar Nov 02 '21 19:11 austinbutler