diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index a8b35c1b..bb62c4d6 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -13,23 +13,21 @@ withr::defer( testthat::teardown_env() ) -if (dir.exists(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"))) { - jdbcDriverFolder <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER") -} else { - jdbcDriverFolder <- "~/.jdbcDrivers" - dir.create(jdbcDriverFolder, showWarnings = FALSE) - baseDatabaseConnectorJarFolder <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER") - Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = jdbcDriverFolder) - withr::defer( - { - unlink(jdbcDriverFolder, recursive = TRUE, force = TRUE) - Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = baseDatabaseConnectorJarFolder) +if (Sys.getenv("DONT_DOWNLOAD_JDBC_DRIVERS", "") != "TRUE") { + oldJarFolder <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER") + Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = tempfile("jdbcDrivers")) + dir.create(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")) + + if (testthat::is_testing()) { + withr::defer({ + unlink(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"), recursive = TRUE, force = TRUE) + Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = oldJarFolder) }, testthat::teardown_env() - ) + ) + } } - # Create a unique ID for the table identifiers tableSuffix <- paste0(substr(.Platform$OS.type, 1, 3), format(Sys.time(), "%y%m%d%H%M%S"), sample(1:100, 1)) tableSuffix <- abs(digest::digest2int(tableSuffix))