Run certain packages tests on TRAVIS only in specific situations?

Hi all,

At our company we have a collection of different packages that help run a certain workflow. Our testing suite (testthat + TRAVIS CI) is divided into two files, one that runs the tests for that specific package only and one that runs the entire workflow. This is to make sure that any new code doesn't break both the package and the general workflow that it helps run.

However, the tests for the general workflow do take a bit longer and we would like to restrict it so that the general workflow tests ONLY run when we do a pull-request to the package (when we have introduced new functionality on a different dev branch) while the package-specific tests keep running everytime we commit/push to the repo.

Wondering if anybody has done this / could share a link to an R package that has done something similar?

2 Likes

To run specific tests on Travis only for Pull Requests, I would suggest taking advantage of the default environment variables set by Travis.

For example, the function below will skip a test on a Travis build that isn't a pull request:

skip_on_travis_commit <- function() {
  on_travis <- Sys.getenv("TRAVIS")
  is_pr <- Sys.getenv("TRAVIS_PULL_REQUEST")
  
  if (identical(on_travis, "true") && identical(is_pr, "false")) {
    skip("Skip workflow test on Travis commit")
  }
  
  return(invisible(TRUE))
}

Then for any workflow test you want to skip, you can add the function call at the beginning:

test_that("A long running workflow test", {
  
  skip_on_travis_commit()
  
  ...
})
2 Likes

Yes this works! Thank you so much @jdblischak! This is MUUUUCH simpler that trying to figure out how to do integration testing. All we have to do is separate our files into normal tests and integration tests and then put skip_on_travis_commit() on the top of the integration tests and that makes everything better!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.