【发布时间】:2021-06-02 01:33:01
【问题描述】:
我想在测试失败的情况下向控制台发送cat() 一些信息(我确信这不会发生,但我无法证明它不会发生),以便我可以调查问题。
现在我的代码大致如下:
testthat::test_that('Maybe fails', {
seed <- as.integer(Sys.time())
set.seed(seed)
testthat::expect_true(maybe_fails(runif(100L)))
testthat::expect_equal(long_vector(runif(100L)), target, tol = 1e-8)
if (failed()) {
cat('seed: ', seed, '\n')
}
})
很遗憾,failed() 不存在。
expect_*() 的返回值似乎没有用,它们只是返回实际参数。
我正在考虑使用all.equal() 再次检查,但这是一个非常丑陋的重复。
【问题讨论】: