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.
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?
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:
-
testthat should set
LANGUAGE
to"C"
(undocumented unless I missed it but from reading gettext's source code that will work, seeguess_category_value()
in https://github.com/autotools-mirror/gettext/blob/fb38661cab30b40b503b55ac8dedcc2a8994932f/gettext-runtime/intl/dcigettext.c#L1465). -
withr should never warn when
LANGUAGE
is set to"C"
.
Handling the remaining part in the testthat issue.