From f188212fdd024f97c4c71727600ab1bdde190e44 Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Wed, 2 Mar 2022 14:19:14 +0100 Subject: [PATCH 1/2] Preserve `lifecycle_verbosity` value in `test_that()` blocks --- NEWS.md | 8 ++++++++ R/local.R | 9 ++++++++- tests/testthat/test-local.R | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index cff4878f9..fbc6b5a21 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# testthat (development) + +* 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. + + # testthat 3.1.3 * Package that explicitly depend on rlang in their description file diff --git a/R/local.R b/R/local.R index bffab84b5..155170415 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") + }) +}) From b44cdc082d233570ce707cdd2b2fffbabd487e7b Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 20 Sep 2022 12:01:46 -0500 Subject: [PATCH 2/2] Fix news --- NEWS.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1cf8a8e9b..1b94d6511 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,13 +1,10 @@ -# testthat (development) +# 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. - -# testthat (development version) - * Fixed a warning in R >=4.2.0 on Windows that occurred when using the C++ testing infrastructure that testthat provides (#1672).