Skip to content

pytest integration

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.5uFLEJrQPx


--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: __main__.py [options] [file_or_dir] [file_or_dir] [...]
__main__.py: error: unrecognized arguments: --inline-snapshot=short-report
  inifile: None
  rootdir: /tmp/tmp.zuc9NXHuOS


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.9F2JRPnwNa


--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.1CHokcut27


--inline-snapshot=disable

Disables all the snapshot logic. snapshot(x) will just return x. This can be used if you think exclude that snapshot logic causes a problem in your tests, or if you want to speedup your CI.

deprecation

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