Open wmay opened 5 years ago
Does testthat::test_path()
solve this problem?
And is this only a problem if you are testing a package that is not installed, but for which you have the source code?
testthat::test_path
doesn't look like it addresses the inst
folder issue.
It is a problem even if the package is installed, because find.package
searches the loaded namespaces before the library paths, so during testing it always returns the path to the source code instead of the installed package path. When running unit tests devtools
/ testthat
use the source code rather than the installed package.
find_schema
looks inpackage_root/sql
to find sql source files. But when running unit tests the files are inpackage_root/inst/sql
. This makes it impossible (as far as I can tell) for an etl extension package to includeetl_init
in unit tests if it includes sql files.devtools
andtestthat
quietly replacesystem.file
with a modified version to keep it working in most unit tests. But those packages can only replacesystem.file
in the package being tested. So if a package importsfind_schema
frometl
, in a unit test whenfind_schema
callssystem.file
it doesn't add the extrainst
folder.I don't know if the
devtools
people provide a way to fix this. Maybefind_schema
could check to see ifpackage_root/sql
exists, and if not then trypackage_root/inst/sql
?You should be able to reproduce this issue with the following steps:
etl
.testthat
and try to testfind_schema
with something like the example below.