在set_reporter之后调用上下文时测试错误消息

时间:2018-01-23 20:44:17

标签: r testthat

我有一个简单的代码片段会引发错误:

library(testthat)
testthat::set_reporter(ListReporter)
context("test1")
# Error in context("test1") : attempt to apply non-function

我做错了什么?

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] testthat_2.0.0

loaded via a namespace (and not attached):
[1] compiler_3.4.3 magrittr_1.5   R6_2.2.2       tools_3.4.3    yaml_2.1.14    rlang_0.1.1  

1 个答案:

答案 0 :(得分:0)

我的错误,设置新记者的正确方法是这段代码(它是一个类):

  testthat::set_reporter(ListReporter$new())