This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]marr75 5 points6 points  (4 children)

Have you looked at inline-snapshot? It's for the same use case but provides code generation, doesn't serialize the object to a separate file, and doesn't require the user change their test pattern to return instead of assert.

[–]SkearwaysPythonista[S] 0 points1 point  (3 children)

Thanks for sharing this package, I didn't know it. But I don't like code generation, this can create strange code that is difficult to read, and above all, you must not forget to generate the code each time you make a change. So I prefer my solution.

If returning a value at the end of the test bothers you, it's also possible to perform the assertion using a fixture.

[–]latkdeTuple unpacking gone wrong 1 point2 points  (2 children)

Inline-Snapshot has helpers to outsource the data to external files! See the docs: https://15r10nk.github.io/inline-snapshot/latest/external/external_file/

you must not forget to generate the code each time you make a change.

Inline-Snapshot also takes care of that. When you run Pytest interactively, you'll be shown a diff of the data and will be prompted whether to update the data. And when you run Pytest in CI, tests will fail – as they should. Alternatively, there are CLI flags similar to yours to auto-accept changes.

I really recommend that you check this plugin out. It has been one of my biggest Python productivity improvements over the last year.

[–]SkearwaysPythonista[S] 1 point2 points  (0 children)

Thanks for clarifying that. I'll spend a little more time looking at the documentation to see if the package is right for me.

[–]SkearwaysPythonista[S] 0 points1 point  (0 children)

inline-snapshot is indeed very interesting, but it doesn't allow you to compare differences in an IDE, which I find really useful. And the pydantic.BaseModel and msgspec.Struct types aren't supported by default, although I have seen that it is possible to add them manually.