Skip to content

Research possibility to add local options to devtools::check() #131

Description

@droomelotdegendt

Context

To protect sensitive data and speed up development, our test suite skips database tests by default. These are switched on interactively in the console using R session options: options(test.run_snapshot = TRUE).

However, standard package checks (like devtools::check()) execute in an isolated, non-interactive background R process. Because these background checks run with a clean state, they do not read our active workspace options() or our .Rprofile.

Consequently, database-dependent tests will always be skipped during local package checks.

Questions to resolve

  1. Is there a clean, native way to pass our testing toggles to the background check process?
  2. Do we want database-dependent snapshot tests to run during devtools::check()?

Initial Research

1. Passing options/environment variables to background checks

  • project-level .Renviron - doesn't work: devtools::check() executes tests inside a temporary folder, ignoring the project-level .Renviron (a user-level .Renviron might work, but probably not a good idea)
  • add argument env_vars - works!: We can pass environment variables directly with devtools::check(env_vars = ...)
  • RStudio Build Options: We can prepend environment variables (e.g.: --env-vars=TEST_RUN_SNAPSHOT=TRUE) to the "Check Package" parameteres in Project Options -> Build Tools

2. Extra problem: the global environment variable test_con

Even if we can run the tests in our background process, our helper function fetch_watina_connection() will stop the tests.

fetch_watina_connection <- function() {
  skip_if_not(
    exists("test_con", envir = .GlobalEnv),
    message = "No active database connection found..."
  )
  return(get("test_con", envir = .GlobalEnv))
}

This function expects an active test_con object inside .GlobalEnv. During a background check, this environment is empty.
How should we solve this?

  • Option A - Keep them skipped: Accept that devtools::check() is strictly offline code testing without a database connection. Database tests are only run interactively via devtools::test().
  • Option B - Automatic connection and teardown in setup.R: If check-specific environment variables are detected (e.g.: Sys.getenv("WATINA_RUN_SNAPSHOT") == "TRUE"), we can modify our setup file to automatically establish the connection in the background .GlobalEnv and cleanly close it (teardown_env()) when the check is finished.
  • Option C - Find a way to detect the test_con variable?

Next Steps

  • Decide whether database connectivity is desired during devtools::check().
  • If yes, decide on a way to pass the necessary variables to devtools::check() (currently the option with env_vars seems the best solution)
  • If yes, assure a watina connection is available in the background process (currently option B seems the best solution)
  • Update the testing README.md and the CONTRIBUTING.md to document how to trigger checks with environment variables.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions