Storing snapshots inline
This looks like a really nice project! I was looking for a snapshot testing library to automate tests that compare some JSON responses. One feature I would really like is to store the snapshots in code. For example, something like this:
def test_foo():
expected_value = snapshot(
{...} # some large dict
)
actual_value = foo()
assert expected_value == actual_value
The reason for this is to keep the expected/snapshotted value close to where it is being used, which makes it a lot easier to inspect the expected value, e.g. in code review.
Although I've never used it, it seems that insta (Rust version) supports this, albeit only for strings. I think native Python objects would be ideal, but storing inline as JSON might be easier.
Hello! I'm not sure what's the best way to tackle inline snapshots so I've been putting it off until now. Recently I've been considering hooking into pytest's assertion rewriting mechanism to allow right-sided snapshots even when the object intercepts equality checks in an incompatible manner. Basically I want to remove the caveats section from the README. I think I can experiment with something using assertion rewriting that would allow the following syntax:
assert foo() == snapshot(
{...} # some large dict
)
I'll try to play around with that when I get the time.
Awesome yeah I think that inline snapshots and removal of those gotchas would be great!
hi, @vberlier. It seems that we got almost the same idea. Unfortunately, I only found your library after writing inline-snapshot, which takes inline snapshots as requested in this issue.
I don't want to advertise my library here but rather let you know that i have already solved the same problem. You can have a look at it if you are interested.