[英]Unit tests for deprecated functions in R package cause warnings during check
I've deprecated several functions in my R package by including a .Deprecated("new_function_name")
line at the start of the function. 我通过在函数.Deprecated("new_function_name")
包含.Deprecated("new_function_name")
行来弃用我的R包中的几个函数。 I had full unit test coverage for those deprecated functions. 对于那些已弃用的函数,我有完整的单元测试覆盖率。 Now those tests produce warnings (because of the deprecation message) and muddy up the results of testthat::test()
and devtools::check().
现在这些测试产生警告(因为弃用消息)并且使testthat::test()
和devtools::check().
的结果testthat::test()
devtools::check().
I could just delete the test coverage for deprecated functions, but it seems like as long as users can still call the functions, I should retain test coverage. 我可以删除已弃用函数的测试覆盖率,但似乎只要用户仍然可以调用函数,我应该保留测试覆盖率。 Is there a way I can keep the tests but avoid the clutter in the result of check()
? 有没有办法可以保持测试,但避免check()
结果的混乱? Eg, tell testthat
to count them as passing if the expect_equal()
still works, ignoring the deprecation warnings? 例如,如果expect_equal()
仍然有效,告诉testthat
将它们计为通过,忽略弃用警告?
.Deprecated
produces a warning. .Deprecated
产生警告。 So you can always temporarily store the output and wrap that in a call to expect_warning
or suppressWarnings
if you don't care to test that it gives a warning. 因此,如果您不想测试它是否发出警告,您可以随时临时存储输出并将其包装在对expect_warning
或suppressWarnings
的调用中。
my_dep_fun <- function(x){
.Deprecated("my_new_fun")
return(x+1)
}
Using this 用这个
> # This is what I expect you're doing right now
> expect_equal(my_dep_fun(3), 4)
Warning message:
'my_dep_fun' is deprecated.
Use 'my_new_fun' instead.
See help("Deprecated")
>
> # If we store and use expect_warning we don't get the warning
> expect_warning(tmp <- my_dep_fun(3))
> expect_equal(tmp, 4)
> # Alternatively...
> suppressWarnings(expect_equal(my_dep_fun(3), 4))
>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.