testthat icon indicating copy to clipboard operation
testthat copied to clipboard

Changing language has no effect when envvar LC_ALL='C.UTF-8'

Open tbrown122387 opened this issue 1 year ago • 8 comments

I had a lot of tests that started not passing on a Docker container. They continue to work on my local machine. When I print the traceback, it's complaining about some environment variable.

If lr is a ListReporter, then I'm printing lr$results$as_list()[[1]]$results

I assume this is the result of some update. How can I cirumvent this behavior and go back to the old behavior?

<expectation_warning/expectation/condition>
Changing language has no effect when envvar LC_ALL='C.UTF-8'
Backtrace:
     â–†
  1. └─global calcGradesForGradescope("hw1.R", "hw1_test.R")
  2.   └─testthat::test_file(test_file, reporter = lr, env = scriptResults)
  3.     └─testthat:::test_files(...)
  4.       └─testthat:::test_files_serial(...)
  5.         ├─testthat::with_reporter(...)
  6.         │ └─base::tryCatch(...)
  7.         │   └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  8.         │     └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
  9.         │       └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 10.         └─base::lapply(...)
 11.           └─testthat (local) FUN(X[[i]], ...)
 12.             └─testthat::source_file(path, env = env(env), desc = desc, error_call = error_call)
 13.               └─testthat:::test_code(test = NULL, code = exprs, env = env, default_reporter = StopReporter$new())
 14.                 ├─base::tryCatch(...)
 15.                 │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 16.                 │   ├─base (local) tryCatchOne(...)
 17.                 │   │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 18.                 │   └─base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
 19.                 │     └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 20.                 │       └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 21.                 ├─base::withCallingHandlers(...)
 22.                 └─base::eval(code, test_env)
 23.                   └─base::eval(code, test_env)
 24.                     └─testthat::test_that(...) at hw1_test.R:117:1
 25.                       └─testthat:::test_code(desc, code, env = parent.frame(), default_reporter = local_interactive_reporter())
 26.                         └─testthat:::testthat_state_condition(before, after, call = sys.call(-1))
 27.                           └─testthat:::waldo_compare(before, after, x_arg = "before", y_arg = "after")
 28.                             └─testthat:::local_reporter_output()
 29.                               └─reporter$local_user_output(.env)
 30.                                 └─testthat::local_reproducible_output(...)
 31.                                   └─withr::local_language(lang, .local_envir = .env)
 32.                                     └─withr:::check_language_envvar("LC_ALL")

tbrown122387 avatar Jan 30 '24 21:01 tbrown122387

Adding LC_ALL= at the beginning of the Rscript line in the shell script fixes this, but this seems hacky. Why does test_file care about environment variables?

tbrown122387 avatar Jan 31 '24 01:01 tbrown122387

This is hitting us as well, was this issue ever resolved?

torbjorn avatar May 29 '24 07:05 torbjorn

@torbjorn I received no response from test that. I ended up having to set environment variables on my own to get things working again

tbrown122387 avatar May 29 '24 13:05 tbrown122387

We downgraded to withr 2.5.0 for now

torbjorn avatar May 29 '24 13:05 torbjorn

See also https://github.com/r-lib/withr/issues/254

fh-mthomson avatar Sep 24 '24 00:09 fh-mthomson

Seems nothing is happening here and nothing is happening in withr.

If this is a feature and behavior that is intended, could someone from either camp at least offer guidance on how to code or test differently so this warning doesn't break things that shouldn't break?

torbjorn avatar Sep 24 '24 07:09 torbjorn

We set these environment variables in an attempt to ensure that you get consistent error message if there are translations present. It looks like we should be able to simplify skip this step if you're not in an environment where translations are possible in the first place.

hadley avatar Oct 22 '24 21:10 hadley

Might be fixed by #1879

hadley avatar Oct 22 '24 22:10 hadley

Still having this issue with testthat 3.2.3 and withr_3.0.2

Image

xcompass avatar Jan 25 '25 18:01 xcompass

@xcompass Looking at the code I don't see what path can lead to getting this result. Could you create a reproducible example please?

lionel- avatar Jan 27 '25 08:01 lionel-