Using filter argument in test_package to skip tests
Asked Answered
D

1

4

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?

Disillusionize answered 26/3, 2014 at 23:29 Comment(4)
I didn't (thanks) but I really don't want CMD check depend on external servers (not just connectivity)Disillusionize
And do you know about the NOT_CRAN envvar?Mansour
That only works within devtools right?Disillusionize
Yes but you can also set up yourself. I don't think you can express what you want without a negative look ahead assertion which only the perl engine supports.Mansour
A
3

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.

Aphonia answered 11/4, 2017 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.