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

Preserve lifecycle_verbosity value in test_that() blocks #1581

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
9 changes: 8 additions & 1 deletion R/local.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-local.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})