Open BenjaminHabert opened 5 years ago
See also #38.
Could this be solved by adding the option to pass a custom comparator / assertion function to assert_match()
?
The API change you are proposing is indeed clearer and more explicit than what I suggested.
I haven't used snapshottest
for a while ; I don't know what would be the impact on the current implementation. I am willing to look into it before December 1st if you are interested.
Feature request: provide a custom comparison function for files.
Current method
At the moment the method
filecmp.cmp()
is used to compare two fileshttps://github.com/syrusakbary/snapshottest/blob/master/snapshottest/file.py#L52
Proposed API change
It would be convenient to provide a comparison function when creating the
FileSnapshot
object:This custom function could be called by
FileSnapshotFormatter
My use case
I am creating screenshots of a website (with selenium and chromedriver). Although the screenshots are very similar, the files are slightly different depending on the environment (my local machine, a docker container in CI). I would like to implement a comparison function that checks that the image difference is no higher than x%.
I think this could be useful in other instances: