Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tell between recorded and real response without logging #394

Closed
deeplook opened this issue Sep 22, 2018 · 3 comments
Closed

Tell between recorded and real response without logging #394

deeplook opened this issue Sep 22, 2018 · 3 comments
Labels
stale Issues and PRs that have had birthdays since last activity. Please feel free to reopen though!

Comments

@deeplook
Copy link

It seems like the only way to tell if a request response actually comes from a cassette or is a real, fresh response of some API is to use the logging mechanism described for debugging here: https://vcrpy.readthedocs.io/en/latest/debugging.html. It would be helpful to have a simpler way without involving the logging machinery, maybe by writing a flag into vcr.VCR objects.

@deeplook
Copy link
Author

Well, something like this might work. Is this the recommended way?

import vcr
from vcr.cassette import Cassette
from vcr.request import Request

path = 'headers.yml'

# execute one request, record response
with vcr.use_cassette(path):
    resp = requests.get('http://httpbin.org/headers')

# test if some request has been recorded 
req = Request('GET', 'http://httpbin.org/headers', 'irrelevant body?', {'foo': 'not checked'})
assert Cassette(None).load(path=path).can_play_response_for(req) == True
assert req in Cassette(None).load(path=path)

@deeplook
Copy link
Author

I'm leaving this open in the hope that something similar might end up in the documentation...

@neozenith neozenith added the stale Issues and PRs that have had birthdays since last activity. Please feel free to reopen though! label Jan 5, 2020
@neozenith
Copy link
Collaborator

A lot of changes have happened to VCRpy since this ticket was opened. As this ticket has become stale and we have a lot of old tickets that need to be groomed, I'm closing this for now to make it easier to see what is still relevant.

However if it is still needed, please feel free to re-open or create a new ticket.

Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues and PRs that have had birthdays since last activity. Please feel free to reopen though!
Projects
None yet
Development

No branches or pull requests

2 participants