使用test_package中的filter参数跳过测试 [英] Using filter argument in test_package to skip tests

查看:146
本文介绍了使用test_package中的filter参数跳过测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆