Open
Description
When running testthat::test_file()
on an external file (i.e. not linked to a package). a change in the snaphot will trigger a error message:
Snapshot of
testcase
to 'external_file/base-histogram.svg' has changed
Runtestthat::snapshot_review('external_file/')
to review changes
The path indicated in testthat::snapshot_review('external_file/')
is however non-informative, leading to No snapshots to update. This does not seem to be just a path issue: adding the correct full path still lead to the same error. It seems on the other hand that using the argument path
will solve the problem?
Reproducible code ran with testthat 3.1.2, not reprexable though:
f <-tempdir()
file_ext <- paste0(f, "/external_file.R")
cat("disp_hist_base <- function() hist(mtcars$disp, breaks=20)\n
test_that('base_histo',{
vdiffr::expect_doppelganger('base histogram', disp_hist_base)})",
file = file_ext)
## run twice
testthat::test_file(file_ext)
testthat::test_file(file_ext)
## now change doc
cat("disp_hist_base <- function() hist(mtcars$disp, breaks=10)\n
test_that('base_histo',{
vdiffr::expect_doppelganger('base histogram', disp_hist_base)})",
file = file_ext)
testthat::test_file(file_ext)
testthat::snapshot_review('external_file/')
testthat::snapshot_review(paste(f, '_snaps/external_file/', sep="/"))
testthat::snapshot_review(path=paste(f))
reprex::reprex()
Example output:
> f <-tempdir()
> file_ext <- paste0(f, "/external_file.R")
>
> cat("disp_hist_base <- function() hist(mtcars$disp, breaks=20)\n
+ test_that('base_histo',{
+ vdiffr::expect_doppelganger('base histogram', disp_hist_base)})",
+ file = file_ext)
>
> ## run twice
> testthat::test_file(file_ext)
══ Testing external_file.R ═════════════════════════════════════════════════════════════════════════════════════════
[ FAIL 0 | WARN 1 | SKIP 0 | PASS 1 ]
── Warning (external_file.R:4:3): base_histo ───────────────────────────────────
Adding new file snapshot: 'tests/testhat/_snaps/base-histogram.svg'
[ FAIL 0 | WARN 1 | SKIP 0 | PASS 1 ]
> testthat::test_file(file_ext)
══ Testing external_file.R ═════════════════════════════════════════════════════════════════════════════════════════
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ] Done!
>
> ## now change doc
> cat("disp_hist_base <- function() hist(mtcars$disp, breaks=10)\n
+ test_that('base_histo',{
+ vdiffr::expect_doppelganger('base histogram', disp_hist_base)})",
+ file = file_ext)
>
> testthat::test_file(file_ext)
══ Testing external_file.R ═════════════════════════════════════════════════════════════════════════════════════════
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]
── Failure (external_file.R:4:3): base_histo ───────────────────────────────────
Snapshot of `testcase` to 'external_file/base-histogram.svg' has changed
Run `testthat::snapshot_review('external_file/')` to review changes
Backtrace:
1. vdiffr::expect_doppelganger("base histogram", disp_hist_base)
at external_file.R:4:2
3. testthat::expect_snapshot_file(...)
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]
>
> testthat::snapshot_review('external_file/')
No snapshots to update
> testthat::snapshot_review(paste(f, '_snaps/external_file/', sep="/"))
No snapshots to update
>
> testthat::snapshot_review(path=paste(f))
Starting Shiny app for snapshot review
ℹ Use Ctrl + C to quit