From 2e2571927f5b09670efdd3b314adfa7967b90682 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 4 Jan 2022 19:59:45 -0600 Subject: [PATCH] [R-package] [docs] fix calculation of R test coverage (fixes #4919) (#4922) * [R-package] [docs] fix calculation of R test coverage (fixes #4919) * use quotes * use in_covr() instead of env variable * Update R-package/README.md Co-authored-by: Nikita Titov * check that covr exists * add covr to suggests * use R_COVR environment variable * Update R-package/tests/testthat/test_lgb.unloader.R Co-authored-by: Nikita Titov Co-authored-by: Nikita Titov --- R-package/README.md | 6 ++++-- R-package/tests/testthat/test_lgb.unloader.R | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/R-package/README.md b/R-package/README.md index d610fe0410a8..56031f6254bc 100644 --- a/R-package/README.md +++ b/R-package/README.md @@ -265,11 +265,13 @@ The example below shows how to generate code coverage for the R package on a mac ```shell # Install -sh build-cran-package.sh +sh build-cran-package.sh \ + --no-build-vignettes # Get coverage Rscript -e " \ - coverage <- covr::package_coverage('./lightgbm_r', type = 'tests', quiet = FALSE); + library(covr); + coverage <- covr::package_coverage('./lightgbm_r', type = 'tests', quiet = FALSE); print(coverage); covr::report(coverage, file = file.path(getwd(), 'coverage.html'), browse = TRUE); " diff --git a/R-package/tests/testthat/test_lgb.unloader.R b/R-package/tests/testthat/test_lgb.unloader.R index 6ae8ee2d35f7..791d825d613c 100644 --- a/R-package/tests/testthat/test_lgb.unloader.R +++ b/R-package/tests/testthat/test_lgb.unloader.R @@ -2,7 +2,13 @@ VERBOSITY <- as.integer( Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") ) +CALCULATING_TEST_COVERAGE <- Sys.getenv("R_COVR", unset = "unset") != "unset" + test_that("lgb.unloader works as expected", { + testthat::skip_if( + condition = CALCULATING_TEST_COVERAGE + , message = "lgb.unloader() tests are skipped when calculating test coverage" + ) data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) @@ -24,6 +30,10 @@ test_that("lgb.unloader works as expected", { }) test_that("lgb.unloader finds all boosters and removes them", { + testthat::skip_if( + condition = CALCULATING_TEST_COVERAGE + , message = "lgb.unloader() tests are skipped when calculating test coverage" + ) data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label)