I'm writing tests for a function that under some conditions will generate warnings. I want to ensure that under the other conditions it does not produce warnings. I don't see an obvious way to easily test that with testthat
. I guess I could do something like:
my.result <- 25
my.func <- function() my.result
expect_equal(
withCallingHandlers(
my.func(), warning=function() stop("A Warning!")
),
my.result
)
or use options(warn=2)
, but I was hoping there would be something like:
expect_no_warnings(my.func())
Am I missing something obvious?