It had been a while since I had submitted a package to CRAN and I seem to be doing something wrong with how I am handling documentation examples and my testing suite. I am using roxygen2 and testthat for both of these tasks. The package largely just wraps API endpoints to provide an R interface to some API. The API needs to be running locally after installing some software (available by download).
In our testing suite, we have some code that downloads and installs the software and runs the API locally so tests can run each time, but we wanted to skip this on CRAN (we thought this was how we were supposed to do it). So all of our tests contain testthat::skip_on_cran().
Similarly, all of our examples in our documentation are wrapped in \dontrun{} for the same reason. We want to avoid running examples which would will fail on CRAN machines which do not have the necessary software and API running.
The tests are being skipped (as desired) on all machines except Debian (for some reason?). So the CRAN submission failed. I emailed the CRAN maintainer to let them know my testthat tests should be skipping on CRAN and they provided the following response:
We do not know testthat and how they can detect that a check is executed on CRAN. At least we do not know how to detect that and ideally this would not be detectable, as people should not hide issue from CRAN. For the case with internet access: You can run on CRAN but define a timeout of few seconds and exit nicely in case it takes too long.
Any suggestions for how I should handle the testing suite on a CRAN submission with this in mind? I was always under the impression that you should skip tests that require internet when running on a CRAN machine. Is this wrong?
Not sure how to diagnose the substantive problem you're having, but FYI: the skip on CRAN check does not know whether something is being run on CRAN; instead, it checks for environment variables asserting that the test is not being run on CRAN.
Thanks for sharing that. Either way, whether the tests know it IS being run on CRAN or rather knows it is NOT on CRAN, shouldn't the tests be skipped on CRAN? Unless the CRAN machines are setting the "NOT_CRAN" env var.
I'd be happy to provide more specifics about my package, but I am mostly just looking for guidance on how others handle potentially long-running tests requiring the internet on CRAN.
I think I have implemented a better solution for checking whether the API connection is available for testing and failing gracefully if not, rather than outright trying to skip tests simply because it's on CRAN.
I think with the way the test suite is setup now (in particular setup.R), the tests should skip if the software cannot be downloaded+installed or the API connection is not available (for any reason), regardless of testing environment.
I think you're exactly right. The testing never got to skip_on_cran() because it errored in the setup code.
I think the new approach avoids this by catching errors in setup.R and then skipping all subsequent test due to the skip_if_not(test_connection()) when the API is not running.