Write multiple tests to the same cassette
See original GitHub issueIs it possible to write multiple tests to the same cassette? If multiple tests are making the same API calls, it’s inefficient to record them again and again, better to use a shared cassette.
This is possible with vcr.use_cassette
, but doesn’t seem to be possible with pytest.mark.vcr
, since the default cassette name is always the test name.
For example:
@pytest.mark.vcr("tests/cassettes/shared_cassette.yaml")
def test_a(): ...
@pytest.mark.vcr("tests/cassettes/shared_cassette.yaml")
def test_b(): ...
In this example, you will still write new cassettes to tests/cassettes/test_a.yaml
and tests/cassettes/test_b.yaml
, rather than using the shared one.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Using multiple cassettes with VCR in one test - Stack Overflow
Try using VCR.insert_cassette which does not require a block. You'll need to call eject_cassette in your tear downs. I tried it and it...
Read more >Multiple requests in one cassette - Google Groups
Hello, I'm writing a test for my subscription UI. The process includes 2 requests, one for authorization and one for charging the card....
Read more >Introduction to unit testing with tape, the basics
The purpose of a unit test is to validate that the code unit performs as expected by executing it with crafted inputs and...
Read more >tape - Testling
This guide covers the ins-and-outs of tape, a simple TAP-producing test library for node and browsers. For an exaustive list of all the...
Read more >Existing VCR cassette requests being re-recorded ... - GitHub
We can commit these appended cassettes all day; but the mere fact is, ... My guess is that there is something else that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it’d be just fine to make it always write to the first cassette specified, while reading from all specified. If someone would need more control than that instead, I suggest making it possible to specify cassette fixtures as test arguments, roughly like pytest currently does with parametrization.
Reference: https://docs.pytest.org/en/latest/example/parametrize.html#parametrizing-conditional-raising (follow the link there for argument inputs types too)
Example:
This would also allow on custom operations being done on a cassette, such as using
.rewind()
- I’m not aware of an easy possibility of being able to do that right now.Other possible usages:
So here is my use case as it is slightly different from what this ticket was originally about: I want to isolate some recordings done in a fixture in a specific cassette so it is not recorded for every test running the fixture.
Example: a fixture that provides a logged in client for a specific API to other tests