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

Ignore some requests? #74

Closed
simon-weber opened this issue Apr 10, 2014 · 5 comments
Closed

Ignore some requests? #74

simon-weber opened this issue Apr 10, 2014 · 5 comments
Assignees

Comments

@simon-weber
Copy link
Contributor

Imagine this code:

# app code
def handle_request():
    requests.get('http://example.com')  # I want to record this

def test_app():
    # Imagine we're doing a live server test.
    # The app is running at localhost, and that handler is mounted at the root.
    with vcr.use_cassette('cassette.yaml'):
        server_response = requests.get('http://localhost/')  # but, this gets recorded too

I'm working around this right now by using pycurl - which VCR.py can't mock - when exercising the app endpoint.

Is there a better way of ignoring some requests? The patch for requests looks pretty deep, and I can't put the vcr context manager inside app code.

@kevin1024
Copy link
Owner

I'm trying to figure out what the API for this should look like. It's hard to disable the patch inside the app code without being able to modify the app code itself.

@simon-weber
Copy link
Contributor Author

It's probably easiest not to actually disable the patch - you're right, that seems difficult - but to introduce a per-host filter in the stub. I'm not too familiar with the inner workings of httplib, but if every set of requests to a host is preceded by a call to connect, you could use it to set a per-stub flag to pass requests through.

Then we could expose something like with_cassette(ignore_hosts=['localhost', '127.0.0.1']).

@jashugan
Copy link

The Ruby VCR lib has ignore some requests implemented. I am particularly interested in ignore_localhost option, however just making available an ignore_request call back or handler would be great as well.

@kevin1024
Copy link
Owner

mm nice, I like the Ruby VCR API.

kevin1024 added a commit that referenced this issue May 4, 2014
Add 2 new options, ignore_localhost and ignore_hosts, which can ignore
requests so they aren't recorded in a cassette.

Closes #74
@simon-weber
Copy link
Contributor Author

💖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants