仅在本地机器上构建包时运行测试

问题描述 投票:0回答:1

假设我正在开发一个 R 包,并且有一些用

R CMD check
执行的测试。

我希望其中一些测试只在我在我的机器上本地构建包时执行,而当包由 CRAN 处理时被跳过。

一个解决方案是在将包上传到 CRAN 之前注释掉那些测试,但这是容易出错的和手动的。

我可以添加一些 if 语句或设置以实现此目的吗?

r unit-testing package cran
1个回答
0
投票

skip_on_cran()
是你需要的。

test_that("skip example", {
  expect_equal(1, 1L)    # this expectation runs
  skip_on_cran()
  expect_equal(1, 2)     # this one skipped
  expect_equal(1, 3)     # this one is also skipped
})
© www.soinside.com 2019 - 2024. All rights reserved.