testthat icon indicating copy to clipboard operation
testthat copied to clipboard

Error condition provided by `expect_snapshot` seems buggy in 3.3.0

Open eitsupi opened this issue 1 month ago • 8 comments

testthat::expect_snapshot(stop("error"), error = TRUE, cnd = TRUE)
── Snapshot ─────────────────────────────────────────────────────────────────────────────────────────
ℹ Can't save or compare to reference when testing interactively.
Code
  stop("error")
Condition <rlang_error>
  Error:
  ! error
─────────────────────────────────────────────────────────────────────────────────────────────────────

The condition seems changed to rlang_error in 3.3.0.

Found in pola-rs/r-polars#1642.

eitsupi avatar Nov 14 '25 16:11 eitsupi

These are now converted to rlang errors in order to get tracebacks if your snapshot errors.

hadley avatar Nov 14 '25 16:11 hadley

These are now converted to rlang errors in order to get tracebacks if your snapshot errors.

I see.

I would appreciate it if this was clearly stated in the news.

eitsupi avatar Nov 14 '25 16:11 eitsupi

Alternatively, I'm wondering if it's possible to give the error a name that makes it immediately obvious that it has been replaced by testthat.

eitsupi avatar Nov 14 '25 16:11 eitsupi

I'm a little confused (not unusual). What does the cnd_class argument now do that helps if it just replaces the class? I think the docs may need updating. Should we move back to expect_snapshot_error() if we want to check the class (to some degree) at the same time as well?

TimTaylor avatar Nov 28 '25 11:11 TimTaylor

Hmmmm, let me see if I can somehow get the best of both worlds.

hadley avatar Dec 01 '25 14:12 hadley

Hi @hadley

tidyterra is also broken in GH actions after this change. My use case was to Rbuildignore the folder tests/testthat/_snaps, as I performed a lot of tests that produced ggplots with rasters (Terra package).

These tests are really useful for me so I could capture lots of the changes introduced in ggplot2 >= 3.5.0, but increased the size of the package exceeding by far the CRAN size limit (hence I ignored them on built).

The approach worked fine and also it worked with testtthat::test_local(), but now this is broken in GH Actions.

tidyterra repo: https://github.com/dieghernan/tidyterra

dieghernan avatar Dec 10 '25 23:12 dieghernan

@dieghernan I think that is another change in the latest testthat and not related to this issue. So I suppose you should create another issue.

https://github.com/r-lib/testthat/blob/bec8f61164a96803550e5aafc7305d323e8558de/NEWS.md?plain=1#L36

eitsupi avatar Dec 11 '25 00:12 eitsupi

@dieghernan yes, please file a new issue.

hadley avatar Dec 11 '25 20:12 hadley