EVOLUTION-MANAGER
Edit File: local_test_context.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Locally set options for maximal test reproducibility</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for local_test_context {testthat}"><tr><td>local_test_context {testthat}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Locally set options for maximal test reproducibility</h2> <h3>Description</h3> <p><code>local_test_context()</code> is run automatically by <code>test_that()</code> but you may want to run it yourself if you want to replicate test results interactively. If run inside a function, the effects are automatically reversed when the function exits; if running in the global environment, use <code><a href="../../withr/html/defer.html">withr::deferred_run()</a></code> to undo. </p> <p><code>local_reproducible_output()</code> is run automatically by <code>test_that()</code> in the 3rd edition. You might want to call it to override the the default settings inside a test, if you want to test Unicode, coloured output, or a non-standard width. </p> <h3>Usage</h3> <pre> local_test_context(.env = parent.frame()) local_reproducible_output( width = 80, crayon = FALSE, unicode = FALSE, rstudio = FALSE, hyperlinks = FALSE, lang = "en", .env = parent.frame() ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.env</code></td> <td> <p>Environment to use for scoping; expert use only.</p> </td></tr> <tr valign="top"><td><code>width</code></td> <td> <p>Value of the <code>"width"</code> option.</p> </td></tr> <tr valign="top"><td><code>crayon</code></td> <td> <p>Determines whether or not crayon (now cli) colour should be applied.</p> </td></tr> <tr valign="top"><td><code>unicode</code></td> <td> <p>Value of the <code>"cli.unicode"</code> option. The test is skipped if <code>l10n_info()$`UTF-8`</code> is <code>FALSE</code>.</p> </td></tr> <tr valign="top"><td><code>rstudio</code></td> <td> <p>Should we pretend that we're inside of RStudio?</p> </td></tr> <tr valign="top"><td><code>hyperlinks</code></td> <td> <p>Should we use ANSI hyperlinks.</p> </td></tr> <tr valign="top"><td><code>lang</code></td> <td> <p>Optionally, supply a BCP47 language code to set the language used for translating error messages. This is a lower case two letter <a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639 country code</a>, optionally followed by "_" or "-" and an upper case two letter <a href="https://en.wikipedia.org/wiki/ISO_3166-2">ISO 3166 region code</a>.</p> </td></tr> </table> <h3>Details</h3> <p><code>local_test_context()</code> sets <code>TESTTHAT = "true"</code>, which ensures that <code><a href="is_testing.html">is_testing()</a></code> returns <code>TRUE</code> and allows code to tell if it is run by testthat. </p> <p>In the third edition, <code>local_test_context()</code> also calls <code>local_reproducible_output()</code> which temporary sets the following options: </p> <ul> <li> <p><code>cli.dynamic = FALSE</code> so that tests assume that they are not run in a dynamic console (i.e. one where you can move the cursor around). </p> </li> <li> <p><code>cli.unicode</code> (default: <code>FALSE</code>) 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. </p> </li> <li> <p><code>cli.condition_width = Inf</code> so that new lines introduced while width-wrapping condition messages don't interfere with message matching. </p> </li> <li> <p><code>crayon.enabled</code> (default: <code>FALSE</code>) suppresses ANSI colours generated by the cli and crayon packages (normally colours are used if cli detects that you're in a terminal that supports colour). </p> </li> <li> <p><code>cli.num_colors</code> (default: <code>1L</code>) Same as the crayon option. </p> </li> <li> <p><code>lifecycle_verbosity = "warning"</code> so that every lifecycle problem always generates a warning (otherwise deprecated functions don't generate a warning every time). </p> </li> <li> <p><code>max.print = 99999</code> so the same number of values are printed. </p> </li> <li> <p><code>OutDec = "."</code> so numbers always uses <code>.</code> as the decimal point (European users sometimes set <code>OutDec = ","</code>). </p> </li> <li> <p><code>rlang_interactive = FALSE</code> so that <code><a href="../../rlang/html/is_interactive.html">rlang::is_interactive()</a></code> returns <code>FALSE</code>, and code that uses it pretends you're in a non-interactive environment. </p> </li> <li> <p><code>useFancyQuotes = FALSE</code> so base R functions always use regular (straight) quotes (otherwise the default is locale dependent, see <code><a href="../../base/html/sQuote.html">sQuote()</a></code> for details). </p> </li> <li> <p><code>width</code> (default: 80) to control the width of printed output (usually this varies with the size of your console). </p> </li></ul> <p>And modifies the following env vars: </p> <ul> <li><p> Unsets <code>RSTUDIO</code>, which ensures that RStudio is never detected as running. </p> </li> <li><p> Sets <code>LANGUAGE = "en"</code>, which ensures that no message translation occurs. </p> </li></ul> <p>Finally, it sets the collation locale to "C", which ensures that character sorting the same regardless of system locale. </p> <h3>Examples</h3> <pre> local({ local_test_context() cat(cli::col_blue("Text will not be colored")) cat(cli::symbol$ellipsis) cat("\n") }) test_that("test ellipsis", { local_reproducible_output(unicode = FALSE) expect_equal(cli::symbol$ellipsis, "...") local_reproducible_output(unicode = TRUE) expect_equal(cli::symbol$ellipsis, "\u2026") }) </pre> <hr /><div style="text-align: center;">[Package <em>testthat</em> version 3.1.5 <a href="00Index.html">Index</a>]</div> </body></html>