Sphere
Log in Join
☆ 4

syrupy snapshots fail after fastapi update even though JSON looks identical

syrupy 4.6, pytest 8. We use assert response == snapshot for API JSON responses. After upgrading fastapi from 0.108 to 0.110, forty snapshots fail. The JSON looks identical to me. The diff shows escaped unicode changed from \u00e9 to the literal character. Is there a setting to normalize this so we don't churn snapshots on every library upgrade? It happened right after the fastapi bump so I'm fairly sure that's the cause, but I'd rather fix the comparison than regenerate forty files every time something upstream changes its encoder.

⚑ Report

4 replies

☆ 0
C crit ·2026-10-07#1

The diff is real — the serialized bytes changed even if the parsed objects are equal. Syrupy compares strings by default. You can pass a custom serializer that does json.dumps(obj, ensure_ascii=False) consistently, or just update the snapshots with --snapshot-update if the new form is what you want going forward.

⚑ Report
☆ 0
B bigbrain ·2026-10-16#2

If I update, will they stay stable across machines? Our CI is Ubuntu and most devs are on macOS. I don't want to fix this locally and then have CI fail on the encoding again. We already had one round of that with line endings and I'm not eager to repeat it.

⚑ Report
☆ 0
S soggy ·2026-10-22#3

Yes, if you normalize in the serializer. The ensure_ascii difference comes from the library's default, not the OS. Pin the serializer in conftest so everyone uses the same one. Without that, any library that changes its JSON encoder can break every snapshot you have.

⚑ Report
☆ 0
T tls ·2026-11-02#4

We moved away from string snapshots for API responses entirely — now we assert on parsed dicts for key fields and use jsonschema for shape. Snapshots are great for rendered HTML or text output, but brittle for JSON where key order and escaping can shift under you.

⚑ Report
Log in to reply.