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

[Bug] Using once record_mode gives error #47

Closed
paxcodes opened this issue Jun 10, 2020 · 7 comments · Fixed by #48
Closed

[Bug] Using once record_mode gives error #47

paxcodes opened this issue Jun 10, 2020 · 7 comments · Fixed by #48

Comments

@paxcodes
Copy link

Problem

Using once gives an error:

vcr.errors.CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ([PATH_OF_CASETTE_FILE]) in your current record mode ('once').
E               No match for the request (<Request (GET) https://postman-echo.com/get?foo1=bar1&foo2=bar2>) was found.
E               No similar requests, that have not been played, found.

I ran this the first time so PATH_OF_CASETTE_FILE shouldn't exist although the error seems to say it exists. I checked the PATH_OF_CASETTE_FILE that the error specifies before I run my test the 2nd time and indeed no such file exists.

To Reproduce

import pytest
import requests

@pytest.mark.vcr(record_mode="once")
def test_vcr():
    response = requests.get("https://postman-echo.com/get?foo1=bar1&foo2=bar2")
    assert response.status_code == 200

Stacktrace

Click to expand!
../../Library/Caches/pypoetry/virtualenvs/featuredproductsswitch-q2O7GQgj-py3.8/lib/python3.8/site-packages/requests/api.py:76: in get
    return request('get', url, params=params, **kwargs)
../../Library/Caches/pypoetry/virtualenvs/featuredproductsswitch-q2O7GQgj-py3.8/lib/python3.8/site-packages/requests/api.py:61: in request
    return session.request(method=method, url=url, **kwargs)
../../Library/Caches/pypoetry/virtualenvs/featuredproductsswitch-q2O7GQgj-py3.8/lib/python3.8/site-packages/requests/sessions.py:530: in request
    resp = self.send(prep, **send_kwargs)
../../Library/Caches/pypoetry/virtualenvs/featuredproductsswitch-q2O7GQgj-py3.8/lib/python3.8/site-packages/requests/sessions.py:643: in send
    r = adapter.send(request, **kwargs)
../../Library/Caches/pypoetry/virtualenvs/featuredproductsswitch-q2O7GQgj-py3.8/lib/python3.8/site-packages/requests/adapters.py:439: in send
    resp = conn.urlopen(
../../Library/Caches/pypoetry/virtualenvs/featuredproductsswitch-q2O7GQgj-py3.8/lib/python3.8/site-packages/urllib3/connectionpool.py:670: in urlopen
    httplib_response = self._make_request(
../../Library/Caches/pypoetry/virtualenvs/featuredproductsswitch-q2O7GQgj-py3.8/lib/python3.8/site-packages/urllib3/connectionpool.py:417: in _make_request
    httplib_response = conn.getresponse(buffering=True)
@Stranger6667
Copy link
Collaborator

Hi @paxcodes

Thank you for reporting this! Indeed it is strange, I'll take a look - a similar code with only VCR.py has different behavior

@Stranger6667
Copy link
Collaborator

The problem is, that record_mode passed in the vcr mark is not passed to VCR. I'll fix that

@paxcodes
Copy link
Author

paxcodes commented Jun 13, 2020 via email

@Stranger6667
Copy link
Collaborator

We have this:

def load_cassette(cassette_path, serializer):
    try:
        with open(cassette_path) as f:
            cassette_content = f.read()
    except IOError:
        return [], []
    return deserialize(cassette_content, serializer)

But it actually should raise an error, but it interferes with some other parts - I am taking a deeper look

@Stranger6667
Copy link
Collaborator

So, CombinedPersister should raise an error only if no requests / responses were loaded from any cassettes. Will fix it soon

@Stranger6667
Copy link
Collaborator

I released a fix in 0.8.1. Let me know how it works for your case

@paxcodes
Copy link
Author

Works perfectly. Thanks once again @Stranger6667!

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