我正在为在某些情况下会生成警告的函数编写测试。我想确保在其他条件下它不会产生警告。我没有看到一个明显的方法来轻松测试它testthat
。我想我可以做类似的事情:
my.result <- 25
my.func <- function() my.result
expect_equal(
withCallingHandlers(
my.func(), warning=function() stop("A Warning!")
),
my.result
)
或使用options(warn=2)
,但我希望会有类似的东西:
expect_no_warnings(my.func())
我错过了一些明显的东西吗?