local_test_context()
sets TESTTHAT = "true"
, which ensures that
is_testing()
returns TRUE
and allows code to tell if it is run by
testthat.
In the third edition, local_test_context()
also calls
local_reproducible_output()
which temporary sets the following options:
cli.dynamic = FALSE
so that tests assume that they are not run in
a dynamic console (i.e. one where you can move the cursor around).
cli.unicode
(default: FALSE
) so that the cli package never generates
unicode output (normally cli uses unicode on Linux/Mac but not Windows).
Windows can't easily save unicode output to disk, so it must be set to
false for consistency.
crayon.enabled
(default: FALSE
) suppresses ANSI colours generated by
the crayon package (normally colours are used if crayon detects that you're
in a terminal that supports colour).
lifecycle_verbosity = "warning"
so that every lifecycle problem always
generates a warning (otherwise deprecated functions don't generate a
warning every time).
OutDec = "."
so numbers always uses .
as the decimal point
(European users sometimes set OutDec = ","
).
rlang_interactive = FALSE
so that rlang::is_interactive()
returns
FALSE
, and code that uses it pretends you're in a non-interactive
environment.
useFancyQuotes = FALSE
so base R functions always use regular (straight)
quotes (otherwise the default is locale dependent, see sQuote()
for
details).
width
(default: 80) to control the width of printed output (usually this
varies with the size of your console).
And modifies the following env vars:
Unsets RSTUDIO
, which ensures that RStudio is never detected as running.
Sets LANGUAGE = "en"
, which ensures that no message translation occurs.
Finally, it sets the collation locale to "C", which ensures that character
sorting the same regardless of system locale.