tophat / syrupy

:pancakes: The sweeter pytest snapshot plugin
https://tophat.github.io/syrupy
Apache License 2.0
481 stars 33 forks source link

Inline snapshot testing #122

Open msrose opened 4 years ago

msrose commented 4 years ago

Opening an issue for discussion purposes, no defined requirements or suggestions for how (or whether) this should be implemented):

See https://jestjs.io/docs/en/snapshot-testing#inline-snapshots for how jest handles inline snapshots.

It would be cool if syrupy could support something this since it's really nice for certain cases.

iamogbz commented 11 months ago

Ignoring the complications of modifying the source code for automatic snapshot insertion, what would the syntax look like?

assert actual_data == snapshot(inline="")

Where the presence of the inline key prevents the snapshot from being written to file and the failure diff shows what needs to be copied into the inline string.

assert actual_data == snapshot(inline="""
  dict({
    'list': list([
      2,
    ]),
    'nested': dict({
      'other': 'value',
    }),
  })
""")

Or maybe it can a snapshot extension instead?

15r10nk commented 8 months ago

hi, I'm the author of inline-snapshot and I found this issue while I was reading through your issues to find inspiration for my own library.

Maybe inline-snapshot provides some inspiration for you, because putting the values into the source code is its the main function.

sneak peek:

from inline_snapshot import snapshot

data = dict(
    {
        "list": list([2]),
        "nested": dict({"other": "value"}),
    }
)

def test_data():
    assert data == snapshot({"list": [2], "nested": {"other": "value"}})