我有一个使用testthat的测试套件,其中包含了R/tests中的几个文件,为了加快测试速度,我希望对它们进行并行测试。在devtools、testthat或其他地方是否有实现的方法来达到这个目的?
我尝试“手动”使用future包,但是stdout的文本呈现是不可读的:
# 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)发布于 2022-07-18 18:33:39
新的testthat >= 3.0引入了并行测试。你只需要在你的描述中添加
Config/testthat/parallel: true
Config/testthat/edition: 3devtools::test()应该并行工作。
见平行小体。了解更多信息
发布于 2020-07-15 22:16:39
由于RUnit的长期用户最近转向了tinytest,您正在寻找的特性已经存在于tinytest中了。我认为在某个时候有人已经或者可能为testthat构建了一个并行测试运行程序,但是在“这里和现在”中,我们确实拥有非常好的行为、良好的文档和从RUnit或testthat转换的线索。
我最喜欢的tinytest特性是包中测试的默认安装、缺少其他依赖项和并行运行程序。
还有另一个警告:我更喜欢这种方式的命令行,而不是一个R提示符,因为可能总是有某种形式的副作用。因此,我给利特勒添加了一个测试运行器wrappre tt.r
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,编写这样的包装器很容易。)
然后我们就做了
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中手动运行:
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问题。
https://stackoverflow.com/questions/62924199
复制相似问题