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.
from inline_snapshot import snapshot
def test_something():
assert 1 == snapshot()
assert 2 <= snapshot(5)
[1;34m> pytest test_something.py --inline-snapshot=create,report
[0m[31mERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --inline-snapshot=create,report
inifile: None
rootdir: /tmp/tmp.uvPw7xwKTF
[0m
--inline-snapshot=short-report¶
give a short report over which changes can be made to the snapshots
[1;34m> pytest test_something.py --inline-snapshot=short-report
[0menvironment: line 10: python: command not found
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
[1;34m> pytest test_something.py --inline-snapshot=report
[0m[31mERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --inline-snapshot=report
inifile: None
rootdir: /tmp/tmp.5UMoUY7rPj
[0m
--inline-snapshot=review¶
Shows a diff report for each category and ask if you want to apply the changes
[1;34m> pytest test_something.py --inline-snapshot=review
[0m[31mERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --inline-snapshot=review
inifile: None
rootdir: /tmp/tmp.0bo3nsDZBi
[0m
--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