ropensci / vcr

Record and replay HTTP requests
https://docs.ropensci.org/vcr
Other
77 stars 12 forks source link

How to make tests work for external PRs in a repo #137

Closed maelle closed 4 years ago

maelle commented 4 years ago

Workflow idea

Problems it solves: one wouldn't need to skip tests based on the presence of an API key.

One could still turn vcr off (and the setting of the key to foobar) for a package check that'd run regularly on a CI service.

sckott commented 4 years ago

thanks @maelle - I like it.

To see if I understand, you're proposing a new vcr helper function wrapping test_package? Or just using existing functions?

maelle commented 4 years ago

I don't know what would make the most sense! vdiffr has a separate function for recording fixtures.

sckott commented 4 years ago

I think (not positive though) that all we'd need to do is document that one could set an env var to whatever (e.g., "foobar") and then tests would run even though a "real" key was not present. does that seem right?

maelle commented 4 years ago

It does, but I'd like for the env var to be set by a line in a test setup file. So the maintainer has to comment out this line to record fixtures, but contributors don't even need to think about changing/setting the env variable.

sckott commented 4 years ago

hmm, okay.

maelle commented 4 years ago

Less work for everyone except for vcr maintainer 😉

maelle commented 4 years ago

I've thought a bit more about this whilst trying to add vcr tests to rhub.

Recording mode

Testing mode (in particular CI, external collaborator, when no API key/token present)

It was quite a revelation for me that vcr cannot handle everything that has to be tweaked in the testing mode. I suppose only examples can help here.

sckott commented 4 years ago

we talked about potentially adding to vcr:

testthat has fxn testthat::is_testing (just sees if the env var TESTTHAT is true) - could be useful

maelle commented 4 years ago

Related PR https://github.com/ropensci/rredlist/pull/41/

maelle commented 4 years ago

with the PR above, I'm not sure anything other than docs is needed in vcr / the http testing book. :thinking:

maelle commented 4 years ago

this will be documented in the book but it might be useful to mention in the docs here, maybe.

sckott commented 4 years ago

sounds good