r-lib/withr

Warnings when running tests using withr

Closed this issue · 6 comments

Using withr 3.0.0:

testthat::test_that("X",{
  testthat::expect_equal(1, 1)
})
#> Warning in check_language_envvar("LC_ALL"): Changing language has no effect
#> when envvar LC_ALL='C.UTF-8'

#> Warning in check_language_envvar("LC_ALL"): Changing language has no effect
#> when envvar LC_ALL='C.UTF-8'
#> Test passed 🎉

Created on 2024-01-25 with reprex v2.1.0

Downgrading to 2.5.2 resolves the issue.

My best guess is that it's being invoked here: https://github.com/r-lib/withr/blob/main/R/language.R#L53

Platform: Posit Workbench, using an image built on top of https://github.com/rstudio/rstudio-docker-products/pkgs/container/r-session-complete/137811113?tag=jammy-2023.09.0--89f567d

@hadley I'm tempted to never warn. Or maybe only warn when the frame is globalenv(), like in lifecycle? But such usage would be quite rare.

hadley commented

Yeah, I think that's fine. But maybe we should export a helper like translations_available() or skip_if_no_translations() so there's some way to opt-out if needed?

Good idea. Should the skip_ helper live in testthat or withr?

hadley commented

I feel like withr? Since that's where the setting is happening?

OTOH most people will probably encounter it from testthat via testthat::local_reproducible_output()? So maybe in testthat?

I now think:

Handling the remaining part in the testthat issue.