testthat parallel - where and when to set Ncpus/TESTTHAT_CPUS to cover both devtools test and check

Hi, I'm trying to implement testthat's parallel testing feature. I've updated my package description file as detailed in the docs, and setting either options(Ncpus=4) or Sys.setenv("TESTTHAT_CPUS"=4) either in my session, or in a .Rprofile file seems to work for me when using devtools::test().

When I run devtools::check() it only runs with 2 CPUs, which is the default, which after a little thought, makes sense as I think the R CMD check is creating a fresh R session, so not inheriting the values.

If I stick the options(Ncpus=4) code in the testthat.R file, devtools::check() does seem to pick this up (I'm aware I should be careful with setting options in tests, but for the purpose of the example, the above works). However, devtools::test() does not.

Including the code in a setup.R in the testthat folder doesn't work, as I think this is submitted after the pool of workers is created, so doesn't come in to force at the right time.

Wondering if there's a better solution than to implement the setting in both a .Rprofile and the testthat.R file. Any help much appreciated. I have a skeleton package where I have implemented the above I can add to git if it would be useful for testing.

1 Like

This topic was automatically closed after 45 days. New replies are no longer allowed.


If you have a query related to it or one of the replies, start a new topic and refer back with a link.