testthat
testthat copied to clipboard
Configure the snapshot directory
I'm working on a project that's using snapshot tests. For confidentiality reasons, we can't commit the snapshots to the main GitHub repository as the documentation recommends. Instead, we've set up another repo (testdata
), hosted on an on-premises server. This repo should include test inputs and CSV-formatted test outputs in addition to the snapshot files themselves. I figured the easiest way to set this up would be to put the _snaps
directory inside the local checkout of testdata
. But I couldn't see a way to configure the snapshot directory; it seems to be hardcoded to tests/testthat/_snaps
(at least in the publicly facing functions; the internals all seem to let you pass in a snapshot directory).
Is a configuration setting to change the snapshot directory something that can be added? Or is there a reasonable workaround for this use case that fits with the spirit of testthat?
Other options I've thought of/tried:
- Just using
tests/testthat/_snaps
as the local checkout oftestdata
. Doesn't work because testthat clears out the snapshot directory after running the tests, obliterating all the test inputs and CSV-formatted outputs. - Making
tests/testthat
the local checkout oftestdata
. Doesn't work because now the tests themselves get caught up in thetestdata
repo, and I can't ignore them without also ignoring them in the main repo. - Automatically copying the files back and forth. This seems to have timing issues; I can't see how to automatically copy existing snapshots from
testdata
before they get locked in as the reference snapshots, and copying new snapshots back intotestdata
should really happen at the same time assnapshot_accept
, so we'd have to use our own function instead ofsnapshot_accept
. - Replacing
_snaps
with a symlink totestdata/_snaps
. Unfortunately, we're stuck on Windows workstations that require administrator permission to make symlinks. I don't want to add "go find an administrator" as a step in the setup procedure, there are enough barriers to adopting a testing workflow as it is.
In any case, all of these seem unnecessarily convoluted compared to just letting me choose where _snaps
goes.
We also have problems with this. We like to use testthat
even for code that isn't an R package. This code gets executed in a cloud environment, and when the code is checked out from our git repo, it's checked out as read-only. Even though we aren't even using snapshots, the _snaps
folders that get written cause us grief.
Similar to @scottporter - our CI runs against R code outside an R package that is in a read-only directory structure. We want to use the _snaps
directory, but treat that location as read-only. We would like failures only reported to screen, or written to some alternate location.