tests/testthat/test-parallel.R

test_that("detect number of cpus to use", {

  withr::local_options(Ncpus = 100L)
  withr::local_envvar(TESTTHAT_CPUS = NA)
  expect_equal(default_num_cpus(), 100L)

  withr::local_options(Ncpus = 100L)
  withr::local_envvar(TESTTHAT_CPUS = 10)
  expect_equal(default_num_cpus(), 100L)

  withr::local_options(list(Ncpus = NULL))
  withr::local_envvar(TESTTHAT_CPUS = NA)
  expect_equal(default_num_cpus(), 2L)

  withr::local_options(list(Ncpus = NULL))
  withr::local_envvar(TESTTHAT_CPUS = NA)
  expect_equal(default_num_cpus(), 2L)

  withr::local_options(list(Ncpus = NULL))
  withr::local_envvar(TESTTHAT_CPUS = 13)
  expect_equal(default_num_cpus(), 13L)
})

test_that("ok", {
  withr::local_envvar(c(TESTTHAT_PARALLEL = "TRUE"))
  suppressMessages(ret <- test_local(
    test_path("test-parallel", "ok"),
    reporter = "silent",
    stop_on_failure = FALSE
  ))
  tdf <- as.data.frame(ret)
  tdf <- tdf[order(tdf$file), ]
  expect_equal(tdf$failed, c(0,1,0))
  expect_equal(tdf$skipped, c(FALSE, FALSE, TRUE))
})

Try the testthat package in your browser

Any scripts or data that you put into this service are public.

testthat documentation built on Jan. 21, 2022, 1:10 a.m.