Using filter argument in test_package to skip tests

為{幸葍}努か 提交于 2019-12-12 11:57:55

问题


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.

Hence my run-all.R contains:

library(testthat)
test_package("mypackage", 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?


回答1:


Use the invert argument:

test_package("mypackage", filter="network", invert=TRUE)

The invert argument eventually gets forwarded to grepl via the ... argument via test_check -> run_tests -> test_dir -> etc. From ?test_dir:

...: Additional arguments passed to 'grepl' to control filtering.



来源:https://stackoverflow.com/questions/22675252/using-filter-argument-in-test-package-to-skip-tests

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!