-
Notifications
You must be signed in to change notification settings - Fork 25
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
How to specify use_cassette
#23
Comments
Currently passing the cassette name into the marker is not supported. If the tests are grouped somehow (say, by class) you could override @pytest.mark.vcr
class CommonCassetteTests:
@pytest.fixture
def vcr_cassette_name(self):
return 'custom'
def test_one(self):
...
def test_two(self):
... Otherwise you can use the # Note: don't mix the marker with explicit usage of "vcr"
def test_common1(vcr):
with vcr.use_cassette('common'):
...
def test_common2(vcr):
with vcr.use_cassette('common'):
... I'm not sure what you mean by adding a decorator for VCR - could you rephrase, or provide an example of what you've tried? |
The latter option worked OK within a pytest fixture, e.g. @pytest.fixture()
def vcr_fixture(uri, query_params) -> str:
with vcr.use_cassette("tests/cassettes/vcr_fixture.yaml"):
response = request.get(uri, query_params)
return response (Maybe it should be a pytest yield fixture instead, but it works as is.) The hope for this feature request is that the name of the cassette could be derived from the name of the fixture function. I'm not familiar with the nested decorators for pytest fixtures, but the suggestion might be something like: @pytest.mark.vcr
@pytest.fixture
def vcr_fixture():
pass # TODO do stuff with HTTP This would maintain a |
Marking a fixture like that seems to be unsupported by pytest: pytest-dev/pytest#3664 |
How about @pytest.fixture()
def shared_cassette(vcr):
with vcr.use_cassette("tests/cassettes/vcr_fixture.yaml"):
yield
def test_something(shared_cassette):
pass # TODO do stuff with HTTP Also, as a side note, setting |
If it's a limitation of pytest, it's too much to ask. Thanks for the tips, close at will. |
Closing this, but I'm still open to ideas about better API for using VCR in fixtures. @valgur is right about overriding |
Might be fixed by #25 |
When there are many tests using the same request/response, what's the best way to ensure they all use the same cassette? The
vcr.use_cassette
API clearly provides an option to name a cassette file. Is this exposed in pytest-vcr? e.g.Is this already noted in the read-the-docs? Where is it explained?
It seems like adding a decorator for VCR to a pytest-fixture does not work, or does it? If so, how?
The text was updated successfully, but these errors were encountered: