-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DVC and syrupy. .dvc tracking files deleted by "pytest --snapshot-update" #694
Comments
Additional note, with the unused snapshots (the .dvc files) pytest exits with an error code. So while every test can pass, the presence of the .dvc files results in a error which will require adjustments to CI/CD pipelines. One such adjustment is to add the |
Hi Jason, I saw your issue after submitting this #703 . I think the issues might be related since the dvc file has the following extension |
We use exactly the same setup as @drjasonharrison for managing our snapshot files with DVC (very convenient!). We hence run into the same issues: when running Would be great one could specify a "file ignore list" for syrupy. Otherwise, it's a fantastic tool! Keep up the good work! |
@hoffch add the @tolgaeren I doubt that the problem is multiple dots in the filename. Syrupy is assuming that all files in the snapshots folder are from running Possible solutions include a "file ignore list" such as a .syrupyignore file, or a better understanding of other tools. The first is general but lacks insight that each snapshot file will also have a separate tracking file. The second would require code changes for each additional tool that might make files in the snapshots folder. Alternatively, DVC could be used to track the root snapshots folder rather than the individual snapshot files or test folders. So that's two workarounds. |
I'd prefer not to have tool specific logic in syrupy if it can be helped. For that reason I like the "ignore" file/config approach. For some context, the reason syrupy considers all file extensions as possible snapshots is because it's possible to write custom extensions with arbitrary extensions. The single file extension makes this quite easy. |
Another option would be a method to tell syrupy that for every snapshot file ignore the additional file with appended end. This would allow dvc files that no longer track snapshots to be flagged as removable. |
Unused snapshot detection logic for reference: https://github.com/tophat/syrupy/blob/5eee3d845cd3d3c4a47ea981911e5d4f8ebe83e0/src/syrupy/report.py#L202 and the default "discover_snapshots" method of the extension class: https://github.com/tophat/syrupy/blob/5eee3d845cd3d3c4a47ea981911e5d4f8ebe83e0/src/syrupy/extensions/base.py#L109 The ignore config is the simplest approach since we could just pass an ignore list to
It's an interesting idea, however if someone is playing around with a custom extension and they rename the file extension, that may cause issues. It also somewhat conflicts with #703. |
Describe the bug
DVC is a tool that combines git and external storage to track large files that shouldn't be added to the git repository but that need to be tracked and stored. For a PNG file like
__snapshots__/test_image/test_image.jpeg
runningwill
.gitignore
entry for the file__snapshots__/test_image/test_image.jpeg
__snapshots__/test_image/test_image.jpeg.dvc
to track the filegit add __snapshots__/test_image/test_image.jpeg.dvc .gitignore
Then you use
git commit; dvc push; git push
to copy everything to the storage and repositories.So the snapshots created by syrupy are still in the working copy of the repository, but now there are .dvc files next to them. A new git clone will not include the syrupy snapshots until
dvc pull
is executed.When I ran pytest, syrupy reported
So I did
pytest --snapshot-update
and the .dvc files under the__snapshots__
directorywere deleted.
git restore
brought them back.To reproduce
Note: This uses bash commands to create a .dvc file that will be deleted
by running
pytest --snapshot-update
. This simplifies the reproduction steps.mkdir dvc-and-syrupy
cd dvc-and-syrupy
pipenv --python 3.7
pipenv shell
git init
wget https://raw.githubusercontent.com/tophat/syrupy/main/tests/examples/test_custom_image_extension.py
python -m pip install pytest syrupy
pytest --snapshot-update
git status
echo "this is a test dvc file" > snapshots/test_custom_image_extension/test_jpeg_image.jpg.dvc
echo "/test_jpeg_image.jpg" >> snapshots/test_custom_image_extension/.gitignore
git add snapshots/ test_custom_image_extension.py
git status
git commit -m "dvc tracking of snapshots"
pytest --snapshot-update
git status
Expected behavior
It would be nice to have a way to tell syrupy that
certain files, or file patterns, under the snapshot folder should be ignored.
Screenshots
N/A
Environment (please complete the following information):
Additional context
Right now I have in my repos, .gitignore, .dockerignore, .dvcignore, .jshintignore,
.npmignore, .prettierignore, .eslintignore..... Perhaps it's a sign that a tool has
reached a certain maturity when it accepts guidance on how to ignore unexpected files in
it's sandbox.
The text was updated successfully, but these errors were encountered: