Skip to content

Commit

Permalink
[R-package] [docs] fix calculation of R test coverage (fixes #4919)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Dec 31, 2021
1 parent af5b40e commit 850d717
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +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
LIGHTGBM_TEST_COVERAGE=true \
Rscript -e " \
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);
Expand Down
10 changes: 10 additions & 0 deletions R-package/tests/testthat/test_lgb.unloader.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
)

CALCULATING_TEST_COVERAGE <- Sys.getenv("LIGHTGBM_TEST_COVERAGE") == "true"

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)
Expand All @@ -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)
Expand Down

0 comments on commit 850d717

Please sign in to comment.