You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/customize_repr.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ def test_enum():
42
42
43
43
inline-snapshot comes with a special implementation for the following types:
44
44
45
-
```python exec="1"
45
+
```python exec="1"
46
46
from inline_snapshot._code_repr import code_repr_dispatch, code_repr
47
47
48
48
for name, obj insorted(
@@ -60,7 +60,7 @@ for name, obj in sorted(
60
60
61
61
Container types like `dict` or `dataclass` need a special implementation because it is necessary that the implementation uses `repr()` for the child elements.
Copy file name to clipboardExpand all lines: docs/eq_snapshot.md
+167-4Lines changed: 167 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,9 +33,31 @@ Example:
33
33
def test_something():
34
34
assert 2 + 40 == snapshot(42)
35
35
```
36
+
## unmanaged snapshot parts
36
37
38
+
inline-snapshots manages everything inside `snapshot(...)`, which means that the developer should not change these parts, but there are cases where it is useful to give the developer a bit more control over the snapshot content.
37
39
38
-
## dirty-equals
40
+
Therefor some types will be ignored by inline-snapshot and will **not be updated or fixed**, even if they cause tests to fail.
41
+
42
+
These types are:
43
+
44
+
* dirty-equals expression
45
+
* dynamic code inside `Is(...)`
46
+
* and snapshots inside snapshots.
47
+
48
+
inline-snapshot is able to handle these types inside the following containers:
49
+
50
+
* list
51
+
* tuple
52
+
* dict
53
+
* namedtuple
54
+
* dataclass
55
+
<!--
56
+
* pydantic models
57
+
* attrs
58
+
-->
59
+
60
+
### dirty-equals
39
61
40
62
It might be, that larger snapshots with many lists and dictionaries contain some values which change frequently and are not relevant for the test.
41
63
They might be part of larger data structures and be difficult to normalize.
@@ -82,7 +104,7 @@ Example:
82
104
83
105
inline-snapshot tries to change only the values that it needs to change in order to pass the equality comparison.
84
106
This allows to replace parts of the snapshot with [dirty-equals](https://dirty-equals.helpmanual.io/latest/) expressions.
85
-
This expressions are preserved as long as the `==` comparison with them is `True`.
107
+
This expressions are preserved even if the `==` comparison with them is `False`.
86
108
87
109
Example:
88
110
@@ -159,8 +181,149 @@ Example:
159
181
)
160
182
```
161
183
162
-
!!! note
163
-
The current implementation looks only into lists, dictionaries and tuples and not into the representation of other data structures.
184
+
### Is(...)
185
+
186
+
`Is()` can be used to put runtime values inside snapshots.
187
+
It tells inline-snapshot that the developer wants control over some part of the snapshot.
Snapshots can be used inside other snapshots in different use cases.
235
+
236
+
#### conditional snapshots
237
+
It is possible to describe version specific parts of snapshots by replacing the specific part with `#!python snapshot() if some_condition else snapshot()`.
238
+
The test has to be executed in each specific condition to fill the snapshots.
239
+
240
+
The following example shows how this can be used to run a tests with two different library versions:
0 commit comments