Question: How can I get testthat
to run in an environment that loads my package, and does not inherit from my package?
Background: A package testthat
runs tests "in an environment that inherits from the package namespace environment" [see docs for test_check ]. This means that it does not guarantee that I performed my export correctly, and this bit me several times.
For example, I have the following code in my package:
foo <- function(x)
UseMethod('foo')
##' @rdname foo
foo.data.frame <- function(x) {
message("foo data.frame")
}
foo.default <- function(x) {
message("foo default")
}
And in my tests the following:
x <- 5:13
foo(x)
This is just great. But if the user installs the package, he will get this error:
Error in UseMethod("foo") :
no applicable method for 'foo' applied to an object of class "c('integer', 'numeric')"
The solution is to place declarations @exports
for the two methods, but it is a bummer that the tests did not catch it.
, . , testthat:::run_tests
, , ?