Reusing vcr cassette in tests

I have a test suit in rtweet but I would like to prevent creating different new cassettes for some tests of different functions that ultimately depend on the data returned by the API.

I could omit the call to the API and store the results somewhere and load it again for a different test, but I would like to do that using the existing vcr. Is there a way that I can load again a cassette from a different test_that?

1 Like

yes if you use the same cassette name but I suspect you’d need to first run the test that will generate the more API calls (unless all the tests using the same cassette do the exact same API calls).

I found an interesting reference: Chapter 30 Managing cassettes | HTTP testing in R

1 Like

Thanks! I relied too much on the google search and didn’t manually inspect the book. I will test if this reuse the existing cassette or simply records it in a different way.

For those reading and not sure where or how to use vcr::check_cassette_names, it is in the tests/testthat/setup-*.R file (where headers can be filtered too)

1 Like