I have a test file that takes a while to run, and I would like to skip this file entirely on CRAN, but still run the tests locally and on GitHub actions. The actual motivating example can be found on GitHub, but for simplicity, here is a smaller example:
# some code that takes a long time to run to create an object used for multiple tests.
Sys.sleep(300)
obj <- list(element1 = "a", element2 = "b")
test_that("something works", {
expect_equal(obj$element1, "a")
})
test_that("something else works", {
expect_equal(obj$element2, "b")
})
I want to skip this file entirely on CRAN. A few solutions I've tried, and why they didn't work:
-
skip_on_cran()
- I tried adding this to the top of the script. This successfully skipped all of the expectations (i.e.,expect_equal()
was skipped in both tests. However, the long code at the beginning still runs, which is the problematic aspect for CRAN. So the tests are skipped, but not the entire file. -
test_check()
with filter - I tried adding a filter to exclude the necessary files. This was close. When I usedevtools::test()
, the files are still run locally, and they are excluded when running R CMD CHECK. But unfortunately they are also excluded when runningcovr::codecov()
on GitHub actions.
Is there a method for running a file of tests locally and on a CI environment, but skipping the file entirely on CRAN?