testthat icon indicating copy to clipboard operation
testthat copied to clipboard

devtools::test() with filter argument creates empty _snaps folder when no snapshots are used

Open slager opened this issue 2 years ago • 1 comments

None of my tests use snapshots. The initial state of my testthat directory is that there is no _snaps subdirectory.

When I run devtools::test() I can see that the _snaps folder is created and then removed during the testing process.

When I run devtools::test() with the filter argument to run a subset of tests, the _snaps folder is created but not removed.

To reproduce, clone the latest version of this testthat repo, open testthat.Rproj, and step through the following code:

# setup paths
snaps_path <- file.path('tests', 'testthat', '_snaps')
snaps_backup_path <- file.path('tests', 'testthat', '_snaps_backup')

# backup existing _snaps folder
file.rename(snaps_path, snaps_backup_path)
#[1] TRUE

# _snaps folder doesn't exist now
file.exists(snaps_path)
#[1] FALSE

# these tests contain no snapshots
devtools::test(filter = '^bare$')
#ℹ Testing testthat
#Starting 1 test process
#✔ | F W  S  OK | Context
#✔ |          4 | bare                                                                  
#                                                                                      
#══ Results 
#Duration: 2.3 s
#[ FAIL 0 | WARN 0 | SKIP 0 | PASS 4 ]

# _snaps folder got created
file.exists(snaps_path)
#[1] TRUE

# restore existing _snaps folder
unlink(snaps_path, recursive = TRUE)
file.rename(snaps_backup_path, snaps_path)
#[1] TRUE

See also:

https://github.com/r-lib/testthat/issues/1180

slager avatar Dec 26 '23 15:12 slager

Is this causing problems for you?

hadley avatar Oct 22 '24 19:10 hadley