You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Broken snapshot causes subsequent snapshots within same test block to be auto-deleted #168
Say I have a test_that block with two expect_doppelganger snapshots, and both snapshots are fine. Then I break the first snapshot so that the plotting code errors. When I run the tests, the first expectation will fail and the second expectation will not get run and thus its associated snapshot file will get auto-deleted. I was not expecting the second snapshot to have its SVG file auto-deleted and I panicked when I first noticed this behavior.
A workaround to this problem is to put every expect_doppelganger in its own test_that block. Then if one breaks, the others will still run. Consider the following test file, which runs three expect_doppelganger snapshots split into two test_that blocks:
If you run this test file, you get three saved snaps: plot-1.svg, plot-2.svg, plot-3.svg. Now break just the "plot-1" expectation by changing TRUE to FALSE, and then re-run the test file. Since the "plot-1" expectation is broken, the plot-2.svg file gets auto-deleted. But since the "plot-3" expectation is in its own block, we don't lose the plot-3.svg file.
There was a closely related issue reported in r-lib/testthat#1393. There the issue, translating to my own example, was that the plot-1.svg file was getting deleted. The issue was fixed by automatically "announcing" the snapshot file before evaluation. But that does not fix my issue of a broken snapshot preventing a subsequent snapshot in the same block from being run.
Could vdiffr somehow announce all the snapshots within a block upfront? If not, I think the current behavior should be documented, possibly with the recommendation to put every expect_doppelganger in its own test_that block. Thanks for your consideration.
Activity