File: in_snapshot.md

package info (click to toggle)
python-inline-snapshot 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: python: 6,888; makefile: 34; sh: 28
file content (47 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download
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
## General

It is possible to check if an value is in a snapshot. The value of the generated snapshot will be a list of all values which are tested.

Example:

=== "original code"
    <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->
    ``` python
    from inline_snapshot import snapshot


    def test_something():
        s = snapshot()

        assert 5 in s
        assert 5 in s
        assert 8 in s

        for v in ["a", "b"]:
            assert v in s
    ```

=== "--inline-snapshot=create"
    <!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->
    ``` python hl_lines="5"
    from inline_snapshot import snapshot


    def test_something():
        s = snapshot([5, 8, "a", "b"])

        assert 5 in s
        assert 5 in s
        assert 8 in s

        for v in ["a", "b"]:
            assert v in s
    ```

## pytest options

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

- `create` create a new value if the snapshot value is undefined.
- `fix` adds a value to the list if it is missing.
- `trim` removes a value from the list if it is not necessary.