-
Notifications
You must be signed in to change notification settings - Fork 340
Closed
Description
To reproduce this issue please run in RStudio in Posit Workbench. It works for MS SQL odbc driver as well, I used SQLite3 here for simplicity. Any other odbc I believe will work as well.
You will notice that first expect_equal(f(), expected) passes fine, and then second, which is nested inside test_that fails.
It seems that the fact that code is wrapped into test_that() is affecting how error messages are being generated inside f() inside DBI::dbGetQuery() inside odbc package, which uses rlang for raising errors. Please double check.
I simplified my issue as much as I could so it may look not very realistic, although it shows the problem, the impact of test_that(). I would expect wrapping into test_that() has no impact on the error messages.
library(testthat)
con <- DBI::dbConnect(odbc::odbc(), .connection_string = "Driver=SQLite3;Database=:memory:")
f <- function() tryCatch(DBI::dbGetQuery(con, "non_sql"), error = function(e) conditionMessage(e))
# generate expected output
expected <- f()
# passes
expect_equal(f(), expected)
# fails
test_that("presence of test_that changes behavior of error message from odbc pkg", {
expect_equal(f(), expected)
})
#-- Failure: presence of test_that changes behavior of error message from odbc pkg --
#f() (`actual`) not equal to `expected` (`expected`).sessionInfo()R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8
[9] LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8
time zone: Europe/Zurich
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] testthat_3.2.1.1
loaded via a namespace (and not attached):
[1] bit_4.5.0 rematch2_2.1.2 crayon_1.5.3 dplyr_1.1.4 compiler_4.4.1 brio_1.1.5
[7] filelock_1.0.3 tidyselect_1.2.1 Rcpp_1.0.13 blob_1.2.4 stringr_1.5.1 snakecase_0.11.1
[13] readxl_1.4.3 R6_2.5.1 generics_0.1.3 diffobj_0.3.5 backports_1.5.0 checkmate_2.3.3
[19] tibble_3.3.0 janitor_2.2.1 desc_1.4.3 rprojroot_2.0.4 lubridate_1.9.3 DBI_1.2.3
[25] pillar_1.9.0 rlang_1.1.4 utf8_1.2.4 stringi_1.8.4 pkgload_1.4.0 bit64_4.5.2
[31] timechange_0.3.0 cli_3.6.3 withr_3.0.1 magrittr_2.0.3 tictoc_1.2.1 irecalc_1.2.99
[37] rstudioapi_0.17.1 rJava_1.0-11 hms_1.1.3 odbc_1.5.0 lifecycle_1.0.4 irecalcdata_1.5.0
[43] waldo_0.5.3 vctrs_0.6.5 glue_1.8.0 data.table_1.16.2 duckdb_1.3.2 cellranger_1.1.0
[49] fansi_1.0.6 purrr_1.0.2 httr_1.4.7 tools_4.4.1 pkgconfig_2.0.3
Metadata
Metadata
Assignees
Labels
No labels