使用test_package中的filter参数跳过测试 [英] Using filter argument in test_package to skip tests
问题描述
我想在R CMD check
期间运行我的包装单元测试,但是跳过需要Internet连接的测试.按照惯例,所有需要Internet的单元测试都在文件名中使用单词network
.
I would like to run my package unit tests during R CMD check
, but skip tests that require an internet connection. By convention, all unit tests that require internet have the word network
in their filename.
因此我的run-all.R
包含:
library(testthat)
test_package("mypackage", filter="^((?!network).)*$")
但是这会给出invalid regular expression
错误.如何指定filter
自变量,以便它运行除包含单词network
的单元测试以外的每个单元测试?
However this gives an invalid regular expression
error. How do I specify the filter
argument such that it runs each unit test except the ones with the word network
in them?
推荐答案
使用invert
参数:
test_package("mypackage", filter="network", invert=TRUE)
invert
参数最终通过test_check
-> run_tests
-> test_dir
->等通过...
参数转发到grepl
.从?test_dir
:
The invert
argument eventually gets forwarded to grepl
via the ...
argument via test_check
-> run_tests
-> test_dir
-> etc. From ?test_dir
:
...:传递给"grepl"的其他参数以控制过滤.
...: Additional arguments passed to 'grepl' to control filtering.
这篇关于使用test_package中的filter参数跳过测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!