1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
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:
``` python
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](categories.md).
These flags can be combined with *report* and *review*.
``` python title="test_something.py"
from inline_snapshot import snapshot
def test_something():
assert 1 == snapshot()
assert 2 <= snapshot(5)
```
```bash exec="1" title="something" result="ansi"
cd $(mktemp -d)
export -n CI
export -n GITHUB_ACTIONS
export FORCE_COLOR=256
export COLUMNS=80
function run(){
echo -en "\x1b[1;34m> "
echo $@
echo -en "\x1b[0m"
$@
echo
}
black -q - > test_something.py << EOF
from inline_snapshot import snapshot
def test_something():
assert 1 == snapshot()
assert 2 <= snapshot(5)
EOF
run pytest test_something.py --inline-snapshot=create,report
```
## --inline-snapshot=short-report
give a short report over which changes can be made to the snapshots
```bash exec="1" title="something" result="ansi"
cd $(mktemp -d)
export -n CI
export -n GITHUB_ACTIONS
export FORCE_COLOR=256
export COLUMNS=80
function run(){
echo -en "\x1b[1;34m> "
echo $@
echo -en "\x1b[0m"
python3 -m $@
echo
}
black -q - > test_something.py << EOF
from inline_snapshot import snapshot
def test_something():
assert 1 == snapshot()
assert 2 <= snapshot(5)
EOF
run pytest test_something.py --inline-snapshot=short-report
```
!!! 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
```bash exec="1" title="something" result="ansi"
cd $(mktemp -d)
export -n CI
export -n GITHUB_ACTIONS
export FORCE_COLOR=256
export COLUMNS=80
function run(){
echo -en "\x1b[1;34m> "
echo $@
echo -en "\x1b[0m"
$@
echo
}
black -q - > test_something.py << EOF
from inline_snapshot import snapshot
def test_something():
assert 1 == snapshot()
assert 2 <= snapshot(5)
EOF
run pytest test_something.py --inline-snapshot=report
```
## --inline-snapshot=review
Shows a diff report for each category and ask if you want to apply the changes
```bash exec="1" title="something" result="ansi"
cd $(mktemp -d)
export -n CI
export -n GITHUB_ACTIONS
export FORCE_COLOR=256
export COLUMNS=80
function run(){
echo -en "\x1b[1;34m> "
echo $@
echo -en "\x1b[0m"
$@
echo
}
black -q - > test_something.py << EOF
from inline_snapshot import snapshot
def test_something():
assert 1 == snapshot()
assert 2 <= snapshot(5)
EOF
yes | run pytest test_something.py --inline-snapshot=review
```
## --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.
!!! info "deprecation"
This option was previously called `--inline-snapshot-disable`
|