syrusakbary / snapshottest

Snapshot Testing utils for Python 📸
MIT License
530 stars 103 forks source link

Snapshot should take snapshot of data at the moment when snapshot is being taken 😁 #158

Open jentyk opened 3 years ago

jentyk commented 3 years ago

I know that title sounds a bit silly, but what I meant is that when the "assert_match" method is run, what should be recorded is a copy of the data, not a reference. It seems that currently what is being recorded is a reference and at the moment of saving the whole snapshot file if the same property is snapshotted twice and it changes in the meantime only the latest value is being saved twice.

rgalanakis commented 3 years ago

To elaborate on this some more: When a snapshot is stored (or matched, and none exists, and store is called), a reference is stored. This reference is formatted into a representation during tearDownClass. This means that if things are active during the comparison (like context managers), they may not be active when the snapshot is written. (we use a context manager to normalize Django model reprs so we can ignore things like FK columns).

I think the fix may be to format the data when it's stored, rather than on save.

15r10nk commented 1 year ago

this is a duplicate of https://github.com/syrusakbary/snapshottest/issues/99