Skip to content

snapshot()[key]

General

It is possible to generate sub-snapshots during runtime. These sub-snapshots can be used like normal snapshots.

Example:

from inline_snapshot import snapshot


def test_something():
    s = snapshot()

    assert s["a"] == 4
    assert s["b"] == 5

from inline_snapshot import snapshot


def test_something():
    s = snapshot({"a": 4, "b": 5})

    assert s["a"] == 4
    assert s["b"] == 5

s[key] can be used with every normal snapshot operation including s[key1][key2].

pytest options

It interacts with the following --inline-snapshot flags:

  • create create a new value if the snapshot value is undefined or create a new sub-snapshot if one is missing.
  • trim remove sub-snapshots if they are no longer needed.

The flags fix and update are applied recursively to all sub-snapshots.