Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-package] [docs] fix calculation of R test coverage (fixes #4919) #4922

Merged
merged 9 commits into from
Jan 5, 2022
6 changes: 4 additions & 2 deletions R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't necessary to make calculating test coverage work, but it does speed up the process a lot.

Since these instructions are only about computing the coverage from tests, it isn't necessary to build the vignettes.

coverage <- covr::package_coverage('./lightgbm_r', type = 'tests', quiet = FALSE);

I found that skipping vignette building saved on the order of 60-90 seconds in the process of computing coverage.


# 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);
"
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("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)
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