[R-pkg-devel] how to skip tests on CRAN but NOT on travis-ci?

Dirk Eddelbuettel edd at debian.org
Sun Jun 21 17:47:11 CEST 2015


Hi Jenny,

And a warm welcome here.  I hope you enjoy this place and its ability to form
questions (and answers) beyond the 140 char limit posed elsewhere. :-)

On 21 June 2015 at 07:46, Jennifer Bryan wrote:
| I hope this is an appropriate to place to ask this. My question involves add-on tools and services, but I think they are in common use and others might have same question.
| 
| I am using testthat for testing and Travis (https://travis-ci.org) for continuous integration.
| 
| I do not want the vast majority of my tests to run on CRAN. They take a long time, require an internet connection, etc. I believe the official testthat solution for this is to use testthat::skip_on_cran() at the beginning of the body of the test.
| 
| However, I DO want these tests to run on Travis. In fact, I'd like to be as crazy strict on Travis as possible. More strict than on CRAN. So running R CMD check on Travis "as CRAN" is no good for me.
| 
| I think this coincides with this unanswered question on stackoverflow:
| http://stackoverflow.com/questions/27557150/check-as-cran-but-do-not-skip-any-tests?lq=1


Environment variables are perfect for this.  Eg in RcppRedis I can in fact
assume Redis to be present on Travis (as Travis has a webby-ish focus where
Redis is common) but am fairly certain win-builder and other machines do not.

So in tests/runUnitTests.R I have (with two typos I fixed here)



## if we know a redis server is set up, we can signal this -- cf .travis.yml
if (Sys.getenv("RunRcppRedisTests") == "yes") runTests <- TRUE

## here is a shortcut: if the user is 'edd' we also run tests
## ought to be wrong on CRAN, win-builder, ...
if (Sys.getenv("USER") == "edd") runTests <- TRUE



which shortly later is used in


## Tests for test run
if (runTests) {
    ## Run tests
    tests <- runTestSuite(testSuite)

    ....




This is generic, and you can surely adapt it from testthat.



In Rcpp we do something pretty similar within the set of test files in order
to remain within the one-minute limit.

So in tests/doRUnit.R we do set an environment variable to turn tests on,
else they are off by default:


## force tests to be executed if in dev release which we define as
## having a sub-release, eg 0.9.15.5 is one whereas 0.9.16 is not
if (length(strsplit(packageDescription("Rcpp")$Version, "\\.")[[1]]) > 3) {	
    if (Sys.getenv("RunAllRcppTests") != "no") { 				
        message("Setting \"RunAllRcppTests\"=\"yes\" for development release\n")
        Sys.setenv("RunAllRcppTests"="yes")
    }
}

    
Hope this helps,  Dirk


-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



More information about the R-package-devel mailing list