Skip to content

Pytest

inline-snapshot provides one pytest option with different flags (create, fix, trim, update, short-report, report, disable).

Snapshot comparisons return always True if you use one of the flags create, fix or review. This is necessary because the whole test needs to be run to fix all snapshots like in this case:

from inline_snapshot import snapshot


def test_something():
    assert 1 == snapshot(5)
    assert 2 <= snapshot(5)

Note

Every flag with the exception of disable and short-report disables the pytest assert-rewriting.

--inline-snapshot=create,fix,trim,update

Approve the changes of the given category. These flags can be combined with report and review.

test_something.py
from inline_snapshot import snapshot


def test_something():
    assert 1 == snapshot()
    assert 2 <= snapshot(5)
> pytest test_something.py --inline-snapshot=create,report
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --inline-snapshot=create,report
  inifile: None
  rootdir: /tmp/tmp.ZztutHWllU

--inline-snapshot=short-report

give a short report over which changes can be made to the snapshots

> pytest test_something.py --inline-snapshot=short-report
ERROR: usage: python3 -m pytest [options] [file_or_dir] [file_or_dir] [...]
python3 -m pytest: error: unrecognized arguments: --inline-snapshot=short-report
  inifile: None
  rootdir: /tmp/tmp.HShBXw0o1t

Info

short-report exists mainly to show that snapshots have changed with enabled pytest assert-rewriting. This option will be replaced with report when this restriction is lifted.

--inline-snapshot=report

Shows a diff report over which changes can be made to the snapshots

> pytest test_something.py --inline-snapshot=report
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --inline-snapshot=report
  inifile: None
  rootdir: /tmp/tmp.qtSdwieBHj

--inline-snapshot=review

Shows a diff report for each category and ask if you want to apply the changes

> pytest test_something.py --inline-snapshot=review
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --inline-snapshot=review
  inifile: None
  rootdir: /tmp/tmp.cjtJjBtzhk

--inline-snapshot=disable

Disables all the snapshot logic. snapshot(x) will just return x and inline-snapshot will not be able to fix snapshots or to generate reports. This can be used if you think that snapshot logic causes a problem in your tests. It is also the default for CI runs.

deprecation

This option was previously called --inline-snapshot-disable