syrupy-project / syrupy

:pancakes: The sweeter pytest snapshot plugin
https://syrupy-project.github.io/syrupy/
Apache License 2.0
553 stars 36 forks source link

Easier usage with floats #913

Open shughes-uk opened 1 month ago

shughes-uk commented 1 month ago

Is your feature request related to a problem? Please describe

We can't use syrupy when we are snapshotting objects with floats in them, due to precision issues.

Describe the solution you'd like

A way to set up a level of precision to match floats, ideally globally for all tests via a config option.

Describe alternatives you've considered

Using custom matchers on an individual attribute basis but thats a giant pain.

Additional context

noahnu commented 3 weeks ago

Using custom matchers on an individual attribute basis but thats a giant pain.

You can use a matcher based on type rather than attribute name.

Regardless, this has come up before. Open to ideas/contributions.

shughes-uk commented 3 weeks ago

Using custom matchers on an individual attribute basis but thats a giant pain.

You can use a matcher based on type rather than attribute name.

Regardless, this has come up before. Open to ideas/contributions.

Interesting, I'm not sure i understand the matcher system based on the docs, I came away with the impression it would simply be asserting an attribute had a specific type. I was hoping I could do something like that but failed and was looking at custom serializers.

Ideally i could just drop in the pytest.approx function, i would be happy to make a docs PR with an example of how to do it if you can show me how!