diff --git a/NEWS.md b/NEWS.md index f26bf901c..1b94d6511 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # testthat (development version) +* The `lifecycle_verbosity` global option is now preserved by + `test_that()` if already set. This makes it possible to set it + outside of `test_that()` blocks, so that it applies to a whole test + file. + * Fixed a warning in R >=4.2.0 on Windows that occurred when using the C++ testing infrastructure that testthat provides (#1672). diff --git a/R/local.R b/R/local.R index fed271428..b9876ce97 100644 --- a/R/local.R +++ b/R/local.R @@ -110,12 +110,19 @@ local_reproducible_output <- function(width = 80, cli.condition_width = Inf, cli.num_colors = if (crayon) 8L else 1L, useFancyQuotes = FALSE, - lifecycle_verbosity = "warning", OutDec = ".", rlang_interactive = FALSE, max.print = 99999, .local_envir = .env, ) + + if (is.null(peek_option("lifecycle_verbosity"))) { + withr::local_options( + .local_envir = .env, + lifecycle_verbosity = "warning" + ) + } + withr::local_envvar(RSTUDIO = NA, .local_envir = .env) withr::local_language(lang, .local_envir = .env) withr::local_collate("C", .local_envir = .env) diff --git a/tests/testthat/test-local.R b/tests/testthat/test-local.R index d3d68ce90..3759acc79 100644 --- a/tests/testthat/test-local.R +++ b/tests/testthat/test-local.R @@ -39,3 +39,10 @@ test_that("can override translation of error messages", { local_reproducible_output(lang = "es") expect_error(mean[[1]], "objeto de tipo") }) + +local({ + local_options(lifecycle_verbosity = "quiet") + test_that("lifecycle verbosity is preserved", { + expect_equal(peek_option("lifecycle_verbosity"), "quiet") + }) +})