Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dis-/ Enable parallel testing locally #1570

Closed
markschat opened this issue Feb 10, 2022 · 4 comments
Closed

Dis-/ Enable parallel testing locally #1570

markschat opened this issue Feb 10, 2022 · 4 comments

Comments

@markschat
Copy link

markschat commented Feb 10, 2022

I divided my tests into several subcategories as Unit, Integration, ...
testthis is a great package leaveraging testthat to run every category by its own.

I would like to achieve the following behaviour:

  • Unit-Tests (and alike): disable parallel testing (fast execution -> no need for parallel execution)
  • Integration-Tests: enable parallel testing

As of now I only aware of enabling parallel testing within the DESCRIPTION file globaly. Is there a possible way to achieve this distinction?

@gaborcsardi
Copy link
Member

I think the only way to achieve this is to have two test suites, and turn on/off parallel testing when they are started, via the env var (see docs).

When using them outside of R CMD check you would need to run the test suite that is not in tests/testthat with

testthat::test_dir("tests/othertests")

@markschat
Copy link
Author

@gaborcsardi Thanks for the hint! Could you specify where to find the "env var switch"-Section within the docs? So far I only read about adding some lines to the DESCRIPTION file.

@gaborcsardi
Copy link
Member

Apologies if it is not the docs, you need to set the TESTTHAT_PARALLEL env var to either TRUE or FALSE.

@markschat
Copy link
Author

markschat commented Feb 10, 2022

Exactly what I was looking for 😀 - thanks a lot! The docs seems to be missing this detail though.

Here´s a short example for posterity using devtools & testthis:

Sys.setenv("TESTTHAT_PARALLEL" = "FALSE")
devtools::test() # run all unit-tests within /testthat (in current process)

Sys.setenv("TESTTHAT_PARALLEL" = "TRUE")
testthis::test_integration() # run all integration-tests within /testthat/integration_tests (in parallel)

Sys.setenv("TESTTHAT_PARALLEL" = "") # clean up

Note that testthis::test_integration currently fails but hopefully will soon be fixed.
Use testthat::test_dir() in the meantime as proposed by @gaborcsardi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants