I have a package where I need to test the creation and manipulation of a folder with testthat. Thus I wrote a test, which
我有一个包,需要使用testthat测试文件夹的创建和操作。于是我写了一个测试
- first creates the folder (using a helper-file) then
- 首先创建文件夹(使用helper文件)。
- do testing (which is fine)
- 做测试(这很好)
- delete the folder in the end (using a test named "test-zz-cleanup.R" to make sure it is the last action in the test).
- 最后删除文件夹(使用名为“测试-清理”的测试。确定这是测试中的最后一个动作)。
Appart from the fact that the helperfile is sourced twice (See here - I found a workaround for that) I run into trouble because building the package also creates the test-folder?
由于helperfile的来源是两次(请参见这里——我找到了解决方法),我遇到了麻烦,因为构建包也创建了测试文件夹?
This only happend, when I went to RStudio -> Tools -> Project Options -> Build Tools -> Create docs with roxygen and check "build and reload".
只有当我去RStudio—>工具—>项目选项—>构建工具—>使用roxygen创建文档并检查“构建和重新加载”时,才会发生这种情况。
I have no clue, why the folder is created! Can anybody help? Of course, the folder should ne be created with the package build!
我不知道为什么要创建这个文件夹!有人能帮忙吗?当然,应该使用包构建创建文件夹!
The example package can be found here
示例包可以在这里找到
Update: Created issue on github-testthat
更新:在github-testthat上创建了问题
1 个解决方案
#1
2
After support from the package owners on Github: roxygen uses devtools::load_all()
, which loads test helpers. If you don't want the code in helpers to be run during devtools::load_all() you should define them in a setup-*
file rather than a helper-*
file.
在Github上的包所有者支持之后:roxygen使用devtools::load_all()来加载测试助手。如果不希望在devtools:::load_all()期间运行helper中的代码,则应该在setup-*文件中定义它们,而不是在helper-*文件中定义它们。
But it seems the issue is gone using latest R/RStudio/devtools versions: now everything is running as expected without any changes suggested above!
但是使用最新的R/RStudio/devtools版本似乎已经解决了这个问题:现在一切都按照预期运行,上面没有建议的任何更改!
#1
2
After support from the package owners on Github: roxygen uses devtools::load_all()
, which loads test helpers. If you don't want the code in helpers to be run during devtools::load_all() you should define them in a setup-*
file rather than a helper-*
file.
在Github上的包所有者支持之后:roxygen使用devtools::load_all()来加载测试助手。如果不希望在devtools:::load_all()期间运行helper中的代码,则应该在setup-*文件中定义它们,而不是在helper-*文件中定义它们。
But it seems the issue is gone using latest R/RStudio/devtools versions: now everything is running as expected without any changes suggested above!
但是使用最新的R/RStudio/devtools版本似乎已经解决了这个问题:现在一切都按照预期运行,上面没有建议的任何更改!