Skip an entire test file on CRAN only

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.
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 use devtools::test(), the files are still run locally, and they are excluded when running R CMD CHECK. But unfortunately they are also excluded when running covr::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?

1 Like

Try putting this on top of the test file:

if (!identical(Sys.getenv("NOT_CRAN"), "true")) return()

This topic was automatically closed after 45 days. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.