首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >devtools::test()并行?

devtools::test()并行?
EN

Stack Overflow用户
提问于 2020-07-15 21:41:57
回答 2查看 167关注 0票数 4

我有一个使用testthat的测试套件,其中包含了R/tests中的几个文件,为了加快测试速度,我希望对它们进行并行测试。在devtoolstestthat或其他地方是否有实现的方法来达到这个目的?

我尝试“手动”使用future包,但是stdout的文本呈现是不可读的:

代码语言:javascript
复制
# Get a vector of test files without "test-" and ".R"
test_files = list.files("tests/testthat", "test-")
test_filters = stringr::str_replace_all(test_files, c("test-|\\.R"), "")

# Run test for each file in parallel
future::plan(future::multiprocess)
future.apply::future_mapply(devtools::test, filter = test_filters)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-07-18 18:33:39

新的testthat >= 3.0引入了并行测试。你只需要在你的描述中添加

代码语言:javascript
复制
Config/testthat/parallel: true
Config/testthat/edition: 3

devtools::test()应该并行工作。

平行小体。了解更多信息

票数 1
EN

Stack Overflow用户

发布于 2020-07-15 22:16:39

由于RUnit的长期用户最近转向了tinytest,您正在寻找的特性已经存在于tinytest中了。我认为在某个时候有人已经或者可能为testthat构建了一个并行测试运行程序,但是在“这里和现在”中,我们确实拥有非常好的行为、良好的文档和从RUnittestthat转换的线索。

我最喜欢的tinytest特性是包中测试的默认安装、缺少其他依赖项和并行运行程序。

还有另一个警告:我更喜欢这种方式的命令行,而不是一个R提示符,因为可能总是有某种形式的副作用。因此,我给利特勒添加了一个测试运行器wrappre tt.r

代码语言:javascript
复制
edd@rob:~$ tt.r -h
Usage: tt.r [-h] [-x] [-a] [-b] [-d] [-f] [-n NCPUS] [-p] [-s] [-z] [ARG...]

-a --all            use test_all mode [default: FALSE]
-b --build          use build-install-test mode [default: FALSE]
-d --directory      use directory mode [default: FALSE]
-f --file           use file mode [default: FALSE]
-n --ncpus NCPUS    use 'ncpus' in parallel [default: getOption]
-p --package        use package mode [default: FALSE]
-s --silent         use silent and do not print result [default: FALSE]
-z --effects        suppress side effects [default: FALSE]
-h --help           show this help text
-x --usage          show help and short example usage 
edd@rob:~$ 

(我应该在这里补充说,由于docopt,编写这样的包装器很容易。)

然后我们就做了

代码语言:javascript
复制
edd@rob:~$ tt.r -n 4 -p anytime
starting worker pid=642068 on localhost:11092 at 17:11:25.636
starting worker pid=642067 on localhost:11092 at 17:11:25.654
starting worker pid=642065 on localhost:11092 at 17:11:25.687
starting worker pid=642066 on localhost:11092 at 17:11:25.689
Running test_gh_issue_12.R............    2 tests OK 
Running test_gh_issue_56.R............    7 tests OK 
Running test_gh_issue_33.R............    2 tests OK 

Running test_all_formats.R............    0 tests    ris or Windows or Release
Running test_assertions.R.............    2 tests OK 
Running test_calc_unique.R............    4 tests OK 
Running test_gh_issue_100.R...........    2 tests OK 
Running test_simple.R.................   34 tests OK 
Running test_utilities.R..............    2 tests OK 
Running test_bulk.R................... 2328 tests OK 
[1] "All ok, 2383 results"
edd@rob:~$ 

你看,有一点点输出被吞没了。

当然,您也可以从R中手动运行:

代码语言:javascript
复制
R> tinytest::test_package("anytime", ncpu=4)
starting worker pid=651865 on localhost:11762 at 17:14:45.970
starting worker pid=651864 on localhost:11762 at 17:14:45.980
starting worker pid=651863 on localhost:11762 at 17:14:45.980
starting worker pid=651862 on localhost:11762 at 17:14:45.984
Running test_gh_issue_12.R............    2 tests
 Exited 'test_all_formats.R' at line 24. Skipping Solaris or Windows or ReleaseOK 
Running test_all_formats.R............    0 tests    
Running test_gh_issue_56.R............    7 tests OK 
Running test_assertions.R.............    2 tests OK 
Running test_gh_issue_33.R............    2 tests OK 
Running test_calc_unique.R............    4 tests OK 
Running test_gh_issue_100.R...........    2 tests OK 
Running test_simple.R.................   34 tests OK 
Running test_utilities.R..............    2 tests OK 
Running test_bulk.R................... 2328 tests OK 
[1] "All ok, 2383 results"
R> 

还有其他运行程序用于文件、目录、build+install+test循环等。嘿,如果在这一切之后,你仍然不喜欢它,马克会把你的钱还给你:)

PS在这里,例如在Rcpp中,我有一些测试“变暗了”,因为它们产生了大量的cmdline噪声,所以只有在选择变量设置时才会发生在包测试中。因此,少数“零测试”运行在上面。这是我的设置,而不是tinytest问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62924199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档