rtestthatcovr

How to include tests with `skip_on_cran()` when calling `covr::package_coverage()`?


I have a few tests with skip_on_cran() in a package. They will be run locally when I use call devtools::test(). However, when calling covr::package_coverage(), it does not run these tests. How to include these tests in the call to covr::package_coverage()?

To reproduce this problem. I created a test repository:

https://github.com/sfcheung/testcovr

This is a sample test file

skip_on_cran()

test_that("Test foo", {
    expect_equal(foo(2), 4)
  })

devtools::test() correctly ran this test locally:

> devtools::test()
ℹ Testing testcovr
✔ | F W S  OK | Context

⠏ |         0 | foo                                                                                                   
✔ |         1 | foo

══ Results ═══════════════════════════════════════════════════════════════════════════════════════════════════════════
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ]

However, covr::package_coverage() does not run that test:

> covr::package_coverage()
testcovr Coverage: 0.00%
R/foo.R: 0.00%

I also tried to use code but it still did not run that test:

> covr::package_coverage(type = "none", code = "devtools::test()")
testcovr Coverage: 0.00%
R/foo.R: 0.00%

Is there any way to run tests with skip_on_cran() when calling covr::package_coverage()?


Solution

  • Try setting the NOT_CRAN variable by executing

    Sys.setenv(NOT_CRAN = "true")
    

    and then calculate coverage as usual via

    covr::package_coverage()