Skip to content

Commit

Permalink
Fail if database is missing (#418)
Browse files Browse the repository at this point in the history
Co-authored-by: Xianying Tan <[email protected]>
  • Loading branch information
krlmlr and shrektan authored Dec 28, 2020
1 parent 5593cdf commit 719bc56
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ skip_unless_has_test_db <- function(expr) {
if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
return(skip("On CRAN"))
}
tryCatch({
DBItest:::connect(expr)

# Failing database connection should fail the test in DBItest backends
if (nzchar(Sys.getenv("DBITEST_BACKENDS"))) {
con <- DBItest:::connect(expr)
DBI::dbDisconnect(con)
TRUE
}, error = function(e) {
skip(paste0("Test database not available:\n'", conditionMessage(e), "'"))
})
} else {
tryCatch({
con <- DBItest:::connect(expr)
DBI::dbDisconnect(con)
TRUE
}, error = function(e) {
skip(paste0("Test database not available:\n'", conditionMessage(e), "'"))
})
}
}

0 comments on commit 719bc56

Please sign in to comment.