--- /srv/rebuilderd/tmp/rebuilderdxkgp2c/inputs/python-inline-snapshot-doc_0.31.0-3_all.deb +++ /srv/rebuilderd/tmp/rebuilderdxkgp2c/out/python-inline-snapshot-doc_0.31.0-3_all.deb ├── file list │ @@ -1,3 +1,3 @@ │ -rw-r--r-- 0 0 0 4 2025-12-30 01:27:08.000000 debian-binary │ -rw-r--r-- 0 0 0 3468 2025-12-30 01:27:08.000000 control.tar.xz │ --rw-r--r-- 0 0 0 2794548 2025-12-30 01:27:08.000000 data.tar.xz │ +-rw-r--r-- 0 0 0 2794556 2025-12-30 01:27:08.000000 data.tar.xz ├── control.tar.xz │ ├── control.tar │ │ ├── ./md5sums │ │ │ ├── ./md5sums │ │ │ │┄ Files differ ├── data.tar.xz │ ├── data.tar │ │ ├── ./usr/share/doc/python-inline-snapshot-doc/html/extra.html │ │ │ @@ -1757,15 +1757,15 @@ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ - Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py │ │ │ + Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py │ │ │
│ │ │ │ │ │ │ │ │
215
│ │ │  216
│ │ │  217
│ │ │  218
│ │ │  219
│ │ │  220
│ │ │  221
│ │ │ @@ -2080,15 +2080,15 @@
│ │ │              
│ │ │ │ │ │ │ │ │
│ │ │ - Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py │ │ │ + Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py │ │ │
308
│ │ │  309
│ │ │  310
│ │ │  311
│ │ │  312
│ │ │  313
│ │ │  314
│ │ │ @@ -2232,15 +2232,15 @@
│ │ │  

│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ - Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py │ │ │ + Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py │ │ │
 72
│ │ │   73
│ │ │   74
│ │ │   75
│ │ │   76
│ │ │   77
│ │ │   78
│ │ │ @@ -2446,15 +2446,15 @@
│ │ │  

│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ - Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py │ │ │ + Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py │ │ │
26
│ │ │  27
│ │ │  28
│ │ │  29
│ │ │  30
│ │ │  31
│ │ │  32
│ │ │ @@ -2591,15 +2591,15 @@
│ │ │  
│ │ │

Tip

│ │ │

The argument of WithoutIds can also be an external WithoutIds(external()) if you want to store a large log in an external file.

│ │ │
│ │ │ │ │ │ │ │ │
│ │ │ - Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py │ │ │ + Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py │ │ │
332
│ │ │  333
│ │ │  334
│ │ │  335
│ │ │  336
│ │ │  337
│ │ │  338
│ │ │ @@ -2804,15 +2804,15 @@
│ │ │  

│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ - Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py │ │ │ + Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py │ │ │
145
│ │ │  146
│ │ │  147
│ │ │  148
│ │ │  149
│ │ │  150
│ │ │  151
│ │ │ ├── html2text {}
│ │ │ │ @@ -138,15 +138,15 @@
│ │ │ │                  snapshot("text can contain "),
│ │ │ │              )
│ │ │ │          }
│ │ │ │      )
│ │ │ │  Tip
│ │ │ │  You can use _@_t_r_a_n_s_f_o_r_m_a_t_i_o_n if you want to use the same transformation multiple
│ │ │ │  times.
│ │ │ │ -Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │ +Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │      @declare_unmanaged
│ │ │ │      class Transformed:
│ │ │ │          """
│ │ │ │          `Transformed` allows you to move transformations of your values from
│ │ │ │  _2_1_5 one side of the `==` to the other.
│ │ │ │  _2_1_6
│ │ │ │  _2_1_7     
│ │ │ │ @@ -272,15 +272,15 @@
│ │ │ │  NNaammee      TTyyppee                 DDeessccrriippttiioonn                            DDeeffaauulltt
│ │ │ │  func      Callable[[Any], Any] functions which is used to transform   rreeqquuiirreedd
│ │ │ │                                 the value which is compared.
│ │ │ │  value     _S_n_a_p_s_h_o_t             the result of the transformation       rreeqquuiirreedd
│ │ │ │                                 this argument is unused and only
│ │ │ │  should_be Any                  reported in the repr() to show you the None
│ │ │ │                                 last transformed value.
│ │ │ │ -Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │ +Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │      def __init__(
│ │ │ │  _3_0_8     self, func: Callable[[Any], Any], value: Snapshot, should_be: Any =
│ │ │ │  _3_0_9 None
│ │ │ │  _3_1_0 ) -> None:
│ │ │ │  _3_1_1     """
│ │ │ │  _3_1_2     Arguments:
│ │ │ │  _3_1_3         func: functions which is used to transform the value which is
│ │ │ │ @@ -332,15 +332,15 @@
│ │ │ │  def test_prints():
│ │ │ │      with prints(
│ │ │ │          stdout=IsStr(),
│ │ │ │          stderr=snapshot("some error\n"),
│ │ │ │      ):
│ │ │ │          print("hello world")
│ │ │ │          print("some error", file=sys.stderr)
│ │ │ │ -Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │ +Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │      @contextlib.contextmanager
│ │ │ │  _ _7_2 def prints(*, stdout: Snapshot[str] = "", stderr: Snapshot[str] = ""):
│ │ │ │  _ _7_3     """Uses `contextlib.redirect_stderr/stdout` to capture the output and
│ │ │ │  _ _7_4     compare it with the snapshots. `dirty_equals.IsStr` can be used to
│ │ │ │  _ _7_5 ignore
│ │ │ │  _ _7_6     the output if needed.
│ │ │ │  _ _7_7
│ │ │ │ @@ -427,15 +427,15 @@
│ │ │ │  from inline_snapshot import snapshot
│ │ │ │  from inline_snapshot.extra import raises
│ │ │ │  
│ │ │ │  
│ │ │ │  def test_raises():
│ │ │ │      with raises(snapshot("ZeroDivisionError: division by zero")):
│ │ │ │          1 / 0
│ │ │ │ -Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │ +Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │     @contextlib.contextmanager
│ │ │ │  _2_6 def raises(exception: Snapshot[str]):
│ │ │ │  _2_7     """Check that an exception is raised.
│ │ │ │  _2_8
│ │ │ │  _2_9     Parameters:
│ │ │ │  _3_0         exception: Snapshot that is compared with `#!python f"{type}:
│ │ │ │  _3_1 {message}"` if an exception occurs, or `#!python ""` if no
│ │ │ │ @@ -510,15 +510,15 @@
│ │ │ │                  )
│ │ │ │              ]
│ │ │ │          }
│ │ │ │      )
│ │ │ │  Tip
│ │ │ │  The argument of WithoutIds can also be an external WithoutIds(external()) if
│ │ │ │  you want to store a large log in an external file.
│ │ │ │ -Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │ +Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │      def transformation(func):
│ │ │ │          """
│ │ │ │  _3_3_2
│ │ │ │  _3_3_3     `@transformation` can be used to bind a function to [Transformed]
│ │ │ │  _3_3_4 [inline_snapshot.extra.Transformed],
│ │ │ │  _3_3_5     which simplifies your code if you want to use the same transformation
│ │ │ │  _3_3_6 multiple times.
│ │ │ │ @@ -600,15 +600,15 @@
│ │ │ │  from warnings import warn
│ │ │ │  
│ │ │ │  
│ │ │ │  def test_warns():
│ │ │ │      with warns(snapshot([(8, "UserWarning: some problem")]),
│ │ │ │  include_line=True):
│ │ │ │          warn("some problem")
│ │ │ │ -Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │ +Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
│ │ │ │      @contextlib.contextmanager
│ │ │ │      def warns(
│ │ │ │          expected_warnings: Snapshot[List[Warning]],
│ │ │ │  _1_4_5     /,
│ │ │ │  _1_4_6     include_line: bool = False,
│ │ │ │  _1_4_7     include_file: bool = False,
│ │ │ │  _1_4_8 ):
│ │ ├── ./usr/share/doc/python-inline-snapshot-doc/html/pytest.html
│ │ │ @@ -1620,47 +1620,47 @@
│ │ │      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.qKNqE0dsEe
│ │ │ +  rootdir: /tmp/tmp.lvlOcq3cE0
│ │ │  
│ │ │  
│ │ │

--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.ZcEO2b3h6K
│ │ │ +  rootdir: /tmp/tmp.H5gg7RyA0B
│ │ │  
│ │ │  
│ │ │
│ │ │

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.GiGD327A0J
│ │ │ +  rootdir: /tmp/tmp.9ENKuE294T
│ │ │  
│ │ │  
│ │ │

--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.lRNFRl03ao
│ │ │ +  rootdir: /tmp/tmp.uXFu4qODzR
│ │ │  
│ │ │  
│ │ │

--inline-snapshot=disable

│ │ │

Disables all the snapshot logic. snapshot(x) will just return x and inline-snapshot will not be able to fix snapshots or to generate reports. │ │ │ This can be used if you think that snapshot logic causes a problem in your tests. It is also the default for CI runs.

│ │ │
│ │ │

deprecation

│ │ │ ├── html2text {} │ │ │ │ @@ -88,43 +88,43 @@ │ │ │ │ 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.qKNqE0dsEe │ │ │ │ + rootdir: /tmp/tmp.lvlOcq3cE0 │ │ │ │ │ │ │ │ ********** ----iinnlliinnee--ssnnaappsshhoott==sshhoorrtt--rreeppoorrtt_?¶ ********** │ │ │ │ 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.ZcEO2b3h6K │ │ │ │ + rootdir: /tmp/tmp.H5gg7RyA0B │ │ │ │ │ │ │ │ Info │ │ │ │ short-report exists mainly to show that snapshots have changed with enabled │ │ │ │ pytest assert-rewriting. This option will be replaced with rreeppoorrtt when this │ │ │ │ restriction is lifted. │ │ │ │ ********** ----iinnlliinnee--ssnnaappsshhoott==rreeppoorrtt_?¶ ********** │ │ │ │ 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.GiGD327A0J │ │ │ │ + rootdir: /tmp/tmp.9ENKuE294T │ │ │ │ │ │ │ │ ********** ----iinnlliinnee--ssnnaappsshhoott==rreevviieeww_?¶ ********** │ │ │ │ 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.lRNFRl03ao │ │ │ │ + rootdir: /tmp/tmp.uXFu4qODzR │ │ │ │ │ │ │ │ ********** ----iinnlliinnee--ssnnaappsshhoott==ddiissaabbllee_?¶ ********** │ │ │ │ Disables all the snapshot logic. snapshot(x) will just return x and inline- │ │ │ │ snapshot will not be able to fix snapshots or to generate reports. This can be │ │ │ │ used if you think that snapshot logic causes a problem in your tests. It is │ │ │ │ also the default for CI runs. │ │ │ │ deprecation │ │ ├── ./usr/share/doc/python-inline-snapshot-doc/html/search/search_index.json │ │ │ ├── Pretty-printed │ │ │ │ @@ -1212,40 +1212,40 @@ │ │ │ │ { │ │ │ │ "location": "extra.html#inline_snapshot.extra", │ │ │ │ "text": "

The following functions are built on top of inline-snapshot and could also be implemented in an extra library. The source is added to the documentation, which allows you to look at how they are implemented and implement similar functions if you need them.

They are part of inline-snapshot because they are generally useful and do not depend on other libraries.

", │ │ │ │ "title": "inline_snapshot.extra" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "extra.html#inline_snapshot.extra.Transformed", │ │ │ │ - "text": "

Transformed allows you to move transformations of your values from one side of the == to the other.

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import Transformed\n\n\ndef test_transform():\n    numbers = [1, 8, 3, 7, 5]\n    assert sorted(numbers) == snapshot()\n    assert numbers == Transformed(sorted, snapshot())\n

Both assertions create the same snapshots.

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import Transformed\n\n\ndef test_transform():\n    numbers = [1, 8, 3, 7, 5]\n    assert sorted(numbers) == snapshot([1, 3, 5, 7, 8])\n    assert numbers == Transformed(sorted, snapshot([1, 3, 5, 7, 8]))\n

Transformed is more flexible to use because you can also use it deep inside data structures. The following example shows how Transformed is used inside a dictionary.

from random import shuffle\nfrom inline_snapshot import snapshot\nfrom inline_snapshot.extra import Transformed\n\n\ndef request():\n    data = [1, 8, 18748, 493]\n    shuffle(data)\n    return {\"name\": \"example\", \"data\": data}\n\n\ndef test_request():\n    assert request() == snapshot(\n        {\n            \"name\": \"example\",\n            \"data\": Transformed(sorted, snapshot([1, 8, 493, 18748])),\n        }\n    )\n

Or to normalize strings.

from inline_snapshot.extra import Transformed\nfrom inline_snapshot import snapshot\nimport re\n\n\nclass Thing:\n    def __repr__(self):\n        return \"<Thing with some random id 152897513>\"\n\n\ndef without_ids(text):\n    return re.sub(r\"<([^0-9]*)[^>]+>\", lambda m: f\"<{m[1]} ...>\", text)\n\n\ndef test_text_with_objects():\n    text = f\"text can contain {Thing()}\"\n\n    assert {\"logs\": text} == snapshot(\n        {\n            \"logs\": Transformed(\n                without_ids,\n                snapshot(\"text can contain <Thing with some random id  ...>\"),\n            )\n        }\n    )\n

Tip

You can use @transformation if you want to use the same transformation multiple times.

Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
@declare_unmanaged\nclass Transformed:\n    \"\"\"\n    `Transformed` allows you to move transformations of your values from one side of the `==` to the other.\n\n    <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n    ``` python\n    from inline_snapshot import snapshot\n    from inline_snapshot.extra import Transformed\n\n\n    def test_transform():\n        numbers = [1, 8, 3, 7, 5]\n        assert sorted(numbers) == snapshot()\n        assert numbers == Transformed(sorted, snapshot())\n    ```\n\n    Both assertions create the same snapshots.\n\n    <!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->\n    ``` python hl_lines=\"7 8\"\n    from inline_snapshot import snapshot\n    from inline_snapshot.extra import Transformed\n\n\n    def test_transform():\n        numbers = [1, 8, 3, 7, 5]\n        assert sorted(numbers) == snapshot([1, 3, 5, 7, 8])\n        assert numbers == Transformed(sorted, snapshot([1, 3, 5, 7, 8]))\n    ```\n\n    `Transformed` is more flexible to use because you can also use it deep inside data structures.\n    The following example shows how `Transformed` is used inside a dictionary.\n\n    <!-- inline-snapshot: create fix first_block outcome-passed=1 -->\n    ``` python\n    from random import shuffle\n    from inline_snapshot import snapshot\n    from inline_snapshot.extra import Transformed\n\n\n    def request():\n        data = [1, 8, 18748, 493]\n        shuffle(data)\n        return {\"name\": \"example\", \"data\": data}\n\n\n    def test_request():\n        assert request() == snapshot(\n            {\n                \"name\": \"example\",\n                \"data\": Transformed(sorted, snapshot([1, 8, 493, 18748])),\n            }\n        )\n    ```\n\n    Or to normalize strings.\n\n    <!-- inline-snapshot: create fix first_block outcome-passed=1 -->\n    ``` python\n    from inline_snapshot.extra import Transformed\n    from inline_snapshot import snapshot\n    import re\n\n\n    class Thing:\n        def __repr__(self):\n            return \"<Thing with some random id 152897513>\"\n\n\n    def without_ids(text):\n        return re.sub(r\"<([^0-9]*)[^>]+>\", lambda m: f\"<{m[1]} ...>\", text)\n\n\n    def test_text_with_objects():\n        text = f\"text can contain {Thing()}\"\n\n        assert {\"logs\": text} == snapshot(\n            {\n                \"logs\": Transformed(\n                    without_ids,\n                    snapshot(\"text can contain <Thing with some random id  ...>\"),\n                )\n            }\n        )\n    ```\n\n\n    !!! Tip\n        You can use [@transformation][inline_snapshot.extra.transformation] if you want to use the same transformation multiple times.\n\n    \"\"\"\n\n    def __init__(\n        self, func: Callable[[Any], Any], value: Snapshot, should_be: Any = None\n    ) -> None:\n        \"\"\"\n        Arguments:\n            func: functions which is used to transform the value which is compared.\n            value: the result of the transformation\n            should_be: this argument is unused and only reported in the `repr()` to show you the last transformed value.\n        \"\"\"\n        self._func = func\n        self._value = value\n        self._last_transformed_value = None\n\n    def __eq__(self, other) -> bool:\n        self._last_transformed_value = self._func(other)\n        return self._last_transformed_value == self._value\n\n    def __repr__(self):\n        if self._last_transformed_value == self._value:\n            return f\"Transformed({code_repr(self._func)}, {self._value})\"\n        else:\n            return f\"Transformed({code_repr(self._func)}, {self._value}, should_be={self._last_transformed_value!r})\"\n
", │ │ │ │ + "text": "

Transformed allows you to move transformations of your values from one side of the == to the other.

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import Transformed\n\n\ndef test_transform():\n    numbers = [1, 8, 3, 7, 5]\n    assert sorted(numbers) == snapshot()\n    assert numbers == Transformed(sorted, snapshot())\n

Both assertions create the same snapshots.

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import Transformed\n\n\ndef test_transform():\n    numbers = [1, 8, 3, 7, 5]\n    assert sorted(numbers) == snapshot([1, 3, 5, 7, 8])\n    assert numbers == Transformed(sorted, snapshot([1, 3, 5, 7, 8]))\n

Transformed is more flexible to use because you can also use it deep inside data structures. The following example shows how Transformed is used inside a dictionary.

from random import shuffle\nfrom inline_snapshot import snapshot\nfrom inline_snapshot.extra import Transformed\n\n\ndef request():\n    data = [1, 8, 18748, 493]\n    shuffle(data)\n    return {\"name\": \"example\", \"data\": data}\n\n\ndef test_request():\n    assert request() == snapshot(\n        {\n            \"name\": \"example\",\n            \"data\": Transformed(sorted, snapshot([1, 8, 493, 18748])),\n        }\n    )\n

Or to normalize strings.

from inline_snapshot.extra import Transformed\nfrom inline_snapshot import snapshot\nimport re\n\n\nclass Thing:\n    def __repr__(self):\n        return \"<Thing with some random id 152897513>\"\n\n\ndef without_ids(text):\n    return re.sub(r\"<([^0-9]*)[^>]+>\", lambda m: f\"<{m[1]} ...>\", text)\n\n\ndef test_text_with_objects():\n    text = f\"text can contain {Thing()}\"\n\n    assert {\"logs\": text} == snapshot(\n        {\n            \"logs\": Transformed(\n                without_ids,\n                snapshot(\"text can contain <Thing with some random id  ...>\"),\n            )\n        }\n    )\n

Tip

You can use @transformation if you want to use the same transformation multiple times.

Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
@declare_unmanaged\nclass Transformed:\n    \"\"\"\n    `Transformed` allows you to move transformations of your values from one side of the `==` to the other.\n\n    <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n    ``` python\n    from inline_snapshot import snapshot\n    from inline_snapshot.extra import Transformed\n\n\n    def test_transform():\n        numbers = [1, 8, 3, 7, 5]\n        assert sorted(numbers) == snapshot()\n        assert numbers == Transformed(sorted, snapshot())\n    ```\n\n    Both assertions create the same snapshots.\n\n    <!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->\n    ``` python hl_lines=\"7 8\"\n    from inline_snapshot import snapshot\n    from inline_snapshot.extra import Transformed\n\n\n    def test_transform():\n        numbers = [1, 8, 3, 7, 5]\n        assert sorted(numbers) == snapshot([1, 3, 5, 7, 8])\n        assert numbers == Transformed(sorted, snapshot([1, 3, 5, 7, 8]))\n    ```\n\n    `Transformed` is more flexible to use because you can also use it deep inside data structures.\n    The following example shows how `Transformed` is used inside a dictionary.\n\n    <!-- inline-snapshot: create fix first_block outcome-passed=1 -->\n    ``` python\n    from random import shuffle\n    from inline_snapshot import snapshot\n    from inline_snapshot.extra import Transformed\n\n\n    def request():\n        data = [1, 8, 18748, 493]\n        shuffle(data)\n        return {\"name\": \"example\", \"data\": data}\n\n\n    def test_request():\n        assert request() == snapshot(\n            {\n                \"name\": \"example\",\n                \"data\": Transformed(sorted, snapshot([1, 8, 493, 18748])),\n            }\n        )\n    ```\n\n    Or to normalize strings.\n\n    <!-- inline-snapshot: create fix first_block outcome-passed=1 -->\n    ``` python\n    from inline_snapshot.extra import Transformed\n    from inline_snapshot import snapshot\n    import re\n\n\n    class Thing:\n        def __repr__(self):\n            return \"<Thing with some random id 152897513>\"\n\n\n    def without_ids(text):\n        return re.sub(r\"<([^0-9]*)[^>]+>\", lambda m: f\"<{m[1]} ...>\", text)\n\n\n    def test_text_with_objects():\n        text = f\"text can contain {Thing()}\"\n\n        assert {\"logs\": text} == snapshot(\n            {\n                \"logs\": Transformed(\n                    without_ids,\n                    snapshot(\"text can contain <Thing with some random id  ...>\"),\n                )\n            }\n        )\n    ```\n\n\n    !!! Tip\n        You can use [@transformation][inline_snapshot.extra.transformation] if you want to use the same transformation multiple times.\n\n    \"\"\"\n\n    def __init__(\n        self, func: Callable[[Any], Any], value: Snapshot, should_be: Any = None\n    ) -> None:\n        \"\"\"\n        Arguments:\n            func: functions which is used to transform the value which is compared.\n            value: the result of the transformation\n            should_be: this argument is unused and only reported in the `repr()` to show you the last transformed value.\n        \"\"\"\n        self._func = func\n        self._value = value\n        self._last_transformed_value = None\n\n    def __eq__(self, other) -> bool:\n        self._last_transformed_value = self._func(other)\n        return self._last_transformed_value == self._value\n\n    def __repr__(self):\n        if self._last_transformed_value == self._value:\n            return f\"Transformed({code_repr(self._func)}, {self._value})\"\n        else:\n            return f\"Transformed({code_repr(self._func)}, {self._value}, should_be={self._last_transformed_value!r})\"\n
", │ │ │ │ "title": "Transformed" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "extra.html#inline_snapshot.extra.Transformed.__init__", │ │ │ │ - "text": "

Parameters:

Name Type Description Default func Callable[[Any], Any]

functions which is used to transform the value which is compared.

required value Snapshot

the result of the transformation

required should_be Any

this argument is unused and only reported in the repr() to show you the last transformed value.

None Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
def __init__(\n    self, func: Callable[[Any], Any], value: Snapshot, should_be: Any = None\n) -> None:\n    \"\"\"\n    Arguments:\n        func: functions which is used to transform the value which is compared.\n        value: the result of the transformation\n        should_be: this argument is unused and only reported in the `repr()` to show you the last transformed value.\n    \"\"\"\n    self._func = func\n    self._value = value\n    self._last_transformed_value = None\n
", │ │ │ │ + "text": "

Parameters:

Name Type Description Default func Callable[[Any], Any]

functions which is used to transform the value which is compared.

required value Snapshot

the result of the transformation

required should_be Any

this argument is unused and only reported in the repr() to show you the last transformed value.

None Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
def __init__(\n    self, func: Callable[[Any], Any], value: Snapshot, should_be: Any = None\n) -> None:\n    \"\"\"\n    Arguments:\n        func: functions which is used to transform the value which is compared.\n        value: the result of the transformation\n        should_be: this argument is unused and only reported in the `repr()` to show you the last transformed value.\n    \"\"\"\n    self._func = func\n    self._value = value\n    self._last_transformed_value = None\n
", │ │ │ │ "title": "__init__(func, value, should_be=None)" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "extra.html#inline_snapshot.extra.prints", │ │ │ │ - "text": "

Uses contextlib.redirect_stderr/stdout to capture the output and compare it with the snapshots. dirty_equals.IsStr can be used to ignore the output if needed.

Parameters:

Name Type Description Default stdout Snapshot[str]

Snapshot that is compared to the recorded output.

'' stderr Snapshot[str]

Snapshot that is compared to the recorded error output.

'' original--inline-snapshot=createignore stdout

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import prints\nimport sys\n\n\ndef test_prints():\n    with prints(stdout=snapshot(), stderr=snapshot()):\n        print(\"hello world\")\n        print(\"some error\", file=sys.stderr)\n

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import prints\nimport sys\n\n\ndef test_prints():\n    with prints(\n        stdout=snapshot(\"hello world\\n\"), stderr=snapshot(\"some error\\n\")\n    ):\n        print(\"hello world\")\n        print(\"some error\", file=sys.stderr)\n

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import prints\nfrom dirty_equals import IsStr\nimport sys\n\n\ndef test_prints():\n    with prints(\n        stdout=IsStr(),\n        stderr=snapshot(\"some error\\n\"),\n    ):\n        print(\"hello world\")\n        print(\"some error\", file=sys.stderr)\n

Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
@contextlib.contextmanager\ndef prints(*, stdout: Snapshot[str] = \"\", stderr: Snapshot[str] = \"\"):\n    \"\"\"Uses `contextlib.redirect_stderr/stdout` to capture the output and\n    compare it with the snapshots. `dirty_equals.IsStr` can be used to ignore\n    the output if needed.\n\n    Parameters:\n        stdout: Snapshot that is compared to the recorded output.\n        stderr: Snapshot that is compared to the recorded error output.\n\n    === \"original\"\n\n        <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n        ``` python\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import prints\n        import sys\n\n\n        def test_prints():\n            with prints(stdout=snapshot(), stderr=snapshot()):\n                print(\"hello world\")\n                print(\"some error\", file=sys.stderr)\n        ```\n\n    === \"--inline-snapshot=create\"\n\n        <!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->\n        ``` python hl_lines=\"7 8 9\"\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import prints\n        import sys\n\n\n        def test_prints():\n            with prints(\n                stdout=snapshot(\"hello world\\\\n\"), stderr=snapshot(\"some error\\\\n\")\n            ):\n                print(\"hello world\")\n                print(\"some error\", file=sys.stderr)\n        ```\n\n    === \"ignore stdout\"\n\n        <!-- inline-snapshot: outcome-passed=1 -->\n        ``` python hl_lines=\"3 9 10\"\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import prints\n        from dirty_equals import IsStr\n        import sys\n\n\n        def test_prints():\n            with prints(\n                stdout=IsStr(),\n                stderr=snapshot(\"some error\\\\n\"),\n            ):\n                print(\"hello world\")\n                print(\"some error\", file=sys.stderr)\n        ```\n    \"\"\"\n\n    with redirect_stdout(io.StringIO()) as stdout_io:\n        with redirect_stderr(io.StringIO()) as stderr_io:\n            yield\n\n    assert stderr_io.getvalue() == stderr\n    assert stdout_io.getvalue() == stdout\n
", │ │ │ │ + "text": "

Uses contextlib.redirect_stderr/stdout to capture the output and compare it with the snapshots. dirty_equals.IsStr can be used to ignore the output if needed.

Parameters:

Name Type Description Default stdout Snapshot[str]

Snapshot that is compared to the recorded output.

'' stderr Snapshot[str]

Snapshot that is compared to the recorded error output.

'' original--inline-snapshot=createignore stdout

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import prints\nimport sys\n\n\ndef test_prints():\n    with prints(stdout=snapshot(), stderr=snapshot()):\n        print(\"hello world\")\n        print(\"some error\", file=sys.stderr)\n

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import prints\nimport sys\n\n\ndef test_prints():\n    with prints(\n        stdout=snapshot(\"hello world\\n\"), stderr=snapshot(\"some error\\n\")\n    ):\n        print(\"hello world\")\n        print(\"some error\", file=sys.stderr)\n

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import prints\nfrom dirty_equals import IsStr\nimport sys\n\n\ndef test_prints():\n    with prints(\n        stdout=IsStr(),\n        stderr=snapshot(\"some error\\n\"),\n    ):\n        print(\"hello world\")\n        print(\"some error\", file=sys.stderr)\n

Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
@contextlib.contextmanager\ndef prints(*, stdout: Snapshot[str] = \"\", stderr: Snapshot[str] = \"\"):\n    \"\"\"Uses `contextlib.redirect_stderr/stdout` to capture the output and\n    compare it with the snapshots. `dirty_equals.IsStr` can be used to ignore\n    the output if needed.\n\n    Parameters:\n        stdout: Snapshot that is compared to the recorded output.\n        stderr: Snapshot that is compared to the recorded error output.\n\n    === \"original\"\n\n        <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n        ``` python\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import prints\n        import sys\n\n\n        def test_prints():\n            with prints(stdout=snapshot(), stderr=snapshot()):\n                print(\"hello world\")\n                print(\"some error\", file=sys.stderr)\n        ```\n\n    === \"--inline-snapshot=create\"\n\n        <!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->\n        ``` python hl_lines=\"7 8 9\"\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import prints\n        import sys\n\n\n        def test_prints():\n            with prints(\n                stdout=snapshot(\"hello world\\\\n\"), stderr=snapshot(\"some error\\\\n\")\n            ):\n                print(\"hello world\")\n                print(\"some error\", file=sys.stderr)\n        ```\n\n    === \"ignore stdout\"\n\n        <!-- inline-snapshot: outcome-passed=1 -->\n        ``` python hl_lines=\"3 9 10\"\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import prints\n        from dirty_equals import IsStr\n        import sys\n\n\n        def test_prints():\n            with prints(\n                stdout=IsStr(),\n                stderr=snapshot(\"some error\\\\n\"),\n            ):\n                print(\"hello world\")\n                print(\"some error\", file=sys.stderr)\n        ```\n    \"\"\"\n\n    with redirect_stdout(io.StringIO()) as stdout_io:\n        with redirect_stderr(io.StringIO()) as stderr_io:\n            yield\n\n    assert stderr_io.getvalue() == stderr\n    assert stdout_io.getvalue() == stdout\n
", │ │ │ │ "title": "prints(*, stdout='', stderr='')" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "extra.html#inline_snapshot.extra.raises", │ │ │ │ - "text": "

Check that an exception is raised.

Parameters:

Name Type Description Default exception Snapshot[str]

Snapshot that is compared with f\"{type}: {message}\" if an exception occurs, or \"<no exception>\" if no exception is raised.

required original--inline-snapshot=create

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import raises\n\n\ndef test_raises():\n    with raises(snapshot()):\n        1 / 0\n

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import raises\n\n\ndef test_raises():\n    with raises(snapshot(\"ZeroDivisionError: division by zero\")):\n        1 / 0\n

Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
@contextlib.contextmanager\ndef raises(exception: Snapshot[str]):\n    \"\"\"Check that an exception is raised.\n\n    Parameters:\n        exception: Snapshot that is compared with `#!python f\"{type}: {message}\"` if an exception occurs, or `#!python \"<no exception>\"` if no exception is raised.\n\n    === \"original\"\n\n        <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n        ``` python\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import raises\n\n\n        def test_raises():\n            with raises(snapshot()):\n                1 / 0\n        ```\n\n    === \"--inline-snapshot=create\"\n\n        <!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->\n        ``` python hl_lines=\"6\"\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import raises\n\n\n        def test_raises():\n            with raises(snapshot(\"ZeroDivisionError: division by zero\")):\n                1 / 0\n        ```\n    \"\"\"\n\n    try:\n        yield\n    except Exception as ex:\n        msg = str(ex)\n        if \"\\n\" in msg:\n            assert f\"{type(ex).__name__}:\\n{ex}\" == exception\n        else:\n            assert f\"{type(ex).__name__}: {ex}\" == exception\n    else:\n        assert \"<no exception>\" == exception\n
", │ │ │ │ + "text": "

Check that an exception is raised.

Parameters:

Name Type Description Default exception Snapshot[str]

Snapshot that is compared with f\"{type}: {message}\" if an exception occurs, or \"<no exception>\" if no exception is raised.

required original--inline-snapshot=create

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import raises\n\n\ndef test_raises():\n    with raises(snapshot()):\n        1 / 0\n

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import raises\n\n\ndef test_raises():\n    with raises(snapshot(\"ZeroDivisionError: division by zero\")):\n        1 / 0\n

Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
@contextlib.contextmanager\ndef raises(exception: Snapshot[str]):\n    \"\"\"Check that an exception is raised.\n\n    Parameters:\n        exception: Snapshot that is compared with `#!python f\"{type}: {message}\"` if an exception occurs, or `#!python \"<no exception>\"` if no exception is raised.\n\n    === \"original\"\n\n        <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n        ``` python\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import raises\n\n\n        def test_raises():\n            with raises(snapshot()):\n                1 / 0\n        ```\n\n    === \"--inline-snapshot=create\"\n\n        <!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->\n        ``` python hl_lines=\"6\"\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import raises\n\n\n        def test_raises():\n            with raises(snapshot(\"ZeroDivisionError: division by zero\")):\n                1 / 0\n        ```\n    \"\"\"\n\n    try:\n        yield\n    except Exception as ex:\n        msg = str(ex)\n        if \"\\n\" in msg:\n            assert f\"{type(ex).__name__}:\\n{ex}\" == exception\n        else:\n            assert f\"{type(ex).__name__}: {ex}\" == exception\n    else:\n        assert \"<no exception>\" == exception\n
", │ │ │ │ "title": "raises(exception)" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "extra.html#inline_snapshot.extra.transformation", │ │ │ │ - "text": "

@transformation can be used to bind a function to Transformed, which simplifies your code if you want to use the same transformation multiple times.

from inline_snapshot.extra import transformation\nfrom inline_snapshot import snapshot\nimport re\n\n\nclass Thing:\n    def __repr__(self):\n        return \"<Thing with some random id 152897513>\"\n\n\n@transformation\ndef WithoutIds(text):\n    return re.sub(r\"<([^0-9]*)[^>]+>\", lambda m: f\"<{m[1]} ...>\", text)\n\n\ndef test_text_with_objects():\n    text = f\"text can contain {Thing()}\"\n\n    assert {\"logs\": [text]} == snapshot(\n        {\n            \"logs\": [\n                WithoutIds(\n                    snapshot(\n                        \"text can contain <Thing with some random id  ...>\"\n                    )\n                )\n            ]\n        }\n    )\n

Tip

The argument of WithoutIds can also be an external WithoutIds(external()) if you want to store a large log in an external file.

Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
def transformation(func):\n    \"\"\"\n\n    `@transformation` can be used to bind a function to [Transformed][inline_snapshot.extra.Transformed],\n    which simplifies your code if you want to use the same transformation multiple times.\n\n    <!-- inline-snapshot: create first_block outcome-passed=1 -->\n    ``` python\n    from inline_snapshot.extra import transformation\n    from inline_snapshot import snapshot\n    import re\n\n\n    class Thing:\n        def __repr__(self):\n            return \"<Thing with some random id 152897513>\"\n\n\n    @transformation\n    def WithoutIds(text):\n        return re.sub(r\"<([^0-9]*)[^>]+>\", lambda m: f\"<{m[1]} ...>\", text)\n\n\n    def test_text_with_objects():\n        text = f\"text can contain {Thing()}\"\n\n        assert {\"logs\": [text]} == snapshot(\n            {\n                \"logs\": [\n                    WithoutIds(\n                        snapshot(\n                            \"text can contain <Thing with some random id  ...>\"\n                        )\n                    )\n                ]\n            }\n        )\n    ```\n\n    !!! Tip\n        The argument of `WithoutIds` can also be an external `WithoutIds(external())` if you want to store a large log in an external file.\n    \"\"\"\n\n    def f(value):\n        return Transformed(func, value)\n\n    return f\n
", │ │ │ │ + "text": "

@transformation can be used to bind a function to Transformed, which simplifies your code if you want to use the same transformation multiple times.

from inline_snapshot.extra import transformation\nfrom inline_snapshot import snapshot\nimport re\n\n\nclass Thing:\n    def __repr__(self):\n        return \"<Thing with some random id 152897513>\"\n\n\n@transformation\ndef WithoutIds(text):\n    return re.sub(r\"<([^0-9]*)[^>]+>\", lambda m: f\"<{m[1]} ...>\", text)\n\n\ndef test_text_with_objects():\n    text = f\"text can contain {Thing()}\"\n\n    assert {\"logs\": [text]} == snapshot(\n        {\n            \"logs\": [\n                WithoutIds(\n                    snapshot(\n                        \"text can contain <Thing with some random id  ...>\"\n                    )\n                )\n            ]\n        }\n    )\n

Tip

The argument of WithoutIds can also be an external WithoutIds(external()) if you want to store a large log in an external file.

Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
def transformation(func):\n    \"\"\"\n\n    `@transformation` can be used to bind a function to [Transformed][inline_snapshot.extra.Transformed],\n    which simplifies your code if you want to use the same transformation multiple times.\n\n    <!-- inline-snapshot: create first_block outcome-passed=1 -->\n    ``` python\n    from inline_snapshot.extra import transformation\n    from inline_snapshot import snapshot\n    import re\n\n\n    class Thing:\n        def __repr__(self):\n            return \"<Thing with some random id 152897513>\"\n\n\n    @transformation\n    def WithoutIds(text):\n        return re.sub(r\"<([^0-9]*)[^>]+>\", lambda m: f\"<{m[1]} ...>\", text)\n\n\n    def test_text_with_objects():\n        text = f\"text can contain {Thing()}\"\n\n        assert {\"logs\": [text]} == snapshot(\n            {\n                \"logs\": [\n                    WithoutIds(\n                        snapshot(\n                            \"text can contain <Thing with some random id  ...>\"\n                        )\n                    )\n                ]\n            }\n        )\n    ```\n\n    !!! Tip\n        The argument of `WithoutIds` can also be an external `WithoutIds(external())` if you want to store a large log in an external file.\n    \"\"\"\n\n    def f(value):\n        return Transformed(func, value)\n\n    return f\n
", │ │ │ │ "title": "transformation(func)" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "extra.html#inline_snapshot.extra.warns", │ │ │ │ - "text": "

Captures warnings with warnings.catch_warnings and compares them against expected warnings.

Parameters:

Name Type Description Default expected_warnings Snapshot[List[Warning]]

Snapshot containing a list of expected warnings.

required include_line bool

If True, each expected warning is a tuple (line_number, message).

False include_file bool

If True, each expected warning is a tuple (filename, message).

False

The format of the expected warning:

  • (filename, line_number, message) if both include_line and include_file are True.
  • (line_number, message) if only include_line is True.
  • (filename, message) if only include_file is True.
  • A string message if both are False.
original--inline-snapshot=create

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import warns\nfrom warnings import warn\n\n\ndef test_warns():\n    with warns(snapshot(), include_line=True):\n        warn(\"some problem\")\n

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import warns\nfrom warnings import warn\n\n\ndef test_warns():\n    with warns(snapshot([(8, \"UserWarning: some problem\")]), include_line=True):\n        warn(\"some problem\")\n

Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/extra.py
@contextlib.contextmanager\ndef warns(\n    expected_warnings: Snapshot[List[Warning]],\n    /,\n    include_line: bool = False,\n    include_file: bool = False,\n):\n    \"\"\"\n    Captures warnings with `warnings.catch_warnings` and compares them against expected warnings.\n\n    Parameters:\n        expected_warnings: Snapshot containing a list of expected warnings.\n        include_line: If `True`, each expected warning is a tuple `(line_number, message)`.\n        include_file: If `True`, each expected warning is a tuple `(filename, message)`.\n\n    The format of the expected warning:\n\n    - `(filename, line_number, message)` if both `include_line` and `include_file` are `True`.\n    - `(line_number, message)` if only `include_line` is `True`.\n    - `(filename, message)` if only `include_file` is `True`.\n    - A string `message` if both are `False`.\n\n    === \"original\"\n\n        <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n        ``` python\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import warns\n        from warnings import warn\n\n\n        def test_warns():\n            with warns(snapshot(), include_line=True):\n                warn(\"some problem\")\n        ```\n\n    === \"--inline-snapshot=create\"\n\n        <!-- inline-snapshot: create fix outcome-passed=1 outcome-errors=1 -->\n        ``` python hl_lines=\"7\"\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import warns\n        from warnings import warn\n\n\n        def test_warns():\n            with warns(snapshot([(8, \"UserWarning: some problem\")]), include_line=True):\n                warn(\"some problem\")\n        ```\n    \"\"\"\n    with warnings.catch_warnings(record=True) as result:\n        warnings.simplefilter(\"always\")\n        yield\n\n    def make_warning(w):\n        message = f\"{w.category.__name__}: {w.message}\"\n        if not include_line and not include_file:\n            return message\n        message = (message,)\n\n        if include_line:\n            message = (w.lineno, *message)\n        if include_file:\n            message = (w.filename, *message)\n\n        return message\n\n    assert [make_warning(w) for w in result] == expected_warnings\n
", │ │ │ │ + "text": "

Captures warnings with warnings.catch_warnings and compares them against expected warnings.

Parameters:

Name Type Description Default expected_warnings Snapshot[List[Warning]]

Snapshot containing a list of expected warnings.

required include_line bool

If True, each expected warning is a tuple (line_number, message).

False include_file bool

If True, each expected warning is a tuple (filename, message).

False

The format of the expected warning:

  • (filename, line_number, message) if both include_line and include_file are True.
  • (line_number, message) if only include_line is True.
  • (filename, message) if only include_file is True.
  • A string message if both are False.
original--inline-snapshot=create

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import warns\nfrom warnings import warn\n\n\ndef test_warns():\n    with warns(snapshot(), include_line=True):\n        warn(\"some problem\")\n

from inline_snapshot import snapshot\nfrom inline_snapshot.extra import warns\nfrom warnings import warn\n\n\ndef test_warns():\n    with warns(snapshot([(8, \"UserWarning: some problem\")]), include_line=True):\n        warn(\"some problem\")\n

Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/extra.py
@contextlib.contextmanager\ndef warns(\n    expected_warnings: Snapshot[List[Warning]],\n    /,\n    include_line: bool = False,\n    include_file: bool = False,\n):\n    \"\"\"\n    Captures warnings with `warnings.catch_warnings` and compares them against expected warnings.\n\n    Parameters:\n        expected_warnings: Snapshot containing a list of expected warnings.\n        include_line: If `True`, each expected warning is a tuple `(line_number, message)`.\n        include_file: If `True`, each expected warning is a tuple `(filename, message)`.\n\n    The format of the expected warning:\n\n    - `(filename, line_number, message)` if both `include_line` and `include_file` are `True`.\n    - `(line_number, message)` if only `include_line` is `True`.\n    - `(filename, message)` if only `include_file` is `True`.\n    - A string `message` if both are `False`.\n\n    === \"original\"\n\n        <!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n        ``` python\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import warns\n        from warnings import warn\n\n\n        def test_warns():\n            with warns(snapshot(), include_line=True):\n                warn(\"some problem\")\n        ```\n\n    === \"--inline-snapshot=create\"\n\n        <!-- inline-snapshot: create fix outcome-passed=1 outcome-errors=1 -->\n        ``` python hl_lines=\"7\"\n        from inline_snapshot import snapshot\n        from inline_snapshot.extra import warns\n        from warnings import warn\n\n\n        def test_warns():\n            with warns(snapshot([(8, \"UserWarning: some problem\")]), include_line=True):\n                warn(\"some problem\")\n        ```\n    \"\"\"\n    with warnings.catch_warnings(record=True) as result:\n        warnings.simplefilter(\"always\")\n        yield\n\n    def make_warning(w):\n        message = f\"{w.category.__name__}: {w.message}\"\n        if not include_line and not include_file:\n            return message\n        message = (message,)\n\n        if include_line:\n            message = (w.lineno, *message)\n        if include_file:\n            message = (w.filename, *message)\n\n        return message\n\n    assert [make_warning(w) for w in result] == expected_warnings\n
", │ │ │ │ "title": "warns(expected_warnings, /, include_line=False, include_file=False)" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "fix_assert.html", │ │ │ │ "text": "", │ │ │ │ "title": "assert x == ..." │ │ │ │ }, │ │ │ │ @@ -1377,30 +1377,30 @@ │ │ │ │ { │ │ │ │ "location": "pytest.html", │ │ │ │ "text": "

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\n\n\ndef test_something():\n    assert 1 == snapshot(5)\n    assert 2 <= snapshot(5)\n

Note

Every flag with the exception of disable and short-report disables the pytest assert-rewriting.

", │ │ │ │ "title": "Pytest" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "pytest.html#-inline-snapshotcreatefixtrimupdate", │ │ │ │ - "text": "

Approve the changes of the given category. These flags can be combined with report and review.

test_something.py
from inline_snapshot import snapshot\n\n\ndef test_something():\n    assert 1 == snapshot()\n    assert 2 <= snapshot(5)\n
> pytest test_something.py --inline-snapshot=create,report\nERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]\npytest: error: unrecognized arguments: --inline-snapshot=create,report\n  inifile: None\n  rootdir: /tmp/tmp.qKNqE0dsEe\n\n
", │ │ │ │ + "text": "

Approve the changes of the given category. These flags can be combined with report and review.

test_something.py
from inline_snapshot import snapshot\n\n\ndef test_something():\n    assert 1 == snapshot()\n    assert 2 <= snapshot(5)\n
> pytest test_something.py --inline-snapshot=create,report\nERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]\npytest: error: unrecognized arguments: --inline-snapshot=create,report\n  inifile: None\n  rootdir: /tmp/tmp.lvlOcq3cE0\n\n
", │ │ │ │ "title": "--inline-snapshot=create,fix,trim,update" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "pytest.html#-inline-snapshotshort-report", │ │ │ │ - "text": "

give a short report over which changes can be made to the snapshots

> pytest test_something.py --inline-snapshot=short-report\nERROR: usage: __main__.py [options] [file_or_dir] [file_or_dir] [...]\n__main__.py: error: unrecognized arguments: --inline-snapshot=short-report\n  inifile: None\n  rootdir: /tmp/tmp.ZcEO2b3h6K\n\n

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.

", │ │ │ │ + "text": "

give a short report over which changes can be made to the snapshots

> pytest test_something.py --inline-snapshot=short-report\nERROR: usage: __main__.py [options] [file_or_dir] [file_or_dir] [...]\n__main__.py: error: unrecognized arguments: --inline-snapshot=short-report\n  inifile: None\n  rootdir: /tmp/tmp.H5gg7RyA0B\n\n

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.

", │ │ │ │ "title": "--inline-snapshot=short-report" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "pytest.html#-inline-snapshotreport", │ │ │ │ - "text": "

Shows a diff report over which changes can be made to the snapshots

> pytest test_something.py --inline-snapshot=report\nERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]\npytest: error: unrecognized arguments: --inline-snapshot=report\n  inifile: None\n  rootdir: /tmp/tmp.GiGD327A0J\n\n
", │ │ │ │ + "text": "

Shows a diff report over which changes can be made to the snapshots

> pytest test_something.py --inline-snapshot=report\nERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]\npytest: error: unrecognized arguments: --inline-snapshot=report\n  inifile: None\n  rootdir: /tmp/tmp.9ENKuE294T\n\n
", │ │ │ │ "title": "--inline-snapshot=report" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "pytest.html#-inline-snapshotreview", │ │ │ │ - "text": "

Shows a diff report for each category and ask if you want to apply the changes

> pytest test_something.py --inline-snapshot=review\nERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]\npytest: error: unrecognized arguments: --inline-snapshot=review\n  inifile: None\n  rootdir: /tmp/tmp.lRNFRl03ao\n\n
", │ │ │ │ + "text": "

Shows a diff report for each category and ask if you want to apply the changes

> pytest test_something.py --inline-snapshot=review\nERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]\npytest: error: unrecognized arguments: --inline-snapshot=review\n  inifile: None\n  rootdir: /tmp/tmp.uXFu4qODzR\n\n
", │ │ │ │ "title": "--inline-snapshot=review" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "pytest.html#-inline-snapshotdisable", │ │ │ │ "text": "

Disables all the snapshot logic. snapshot(x) will just return x and inline-snapshot will not be able to fix snapshots or to generate reports. This can be used if you think that snapshot logic causes a problem in your tests. It is also the default for CI runs.

deprecation

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

", │ │ │ │ "title": "--inline-snapshot=disable" │ │ │ │ }, │ │ │ │ @@ -1477,15 +1477,15 @@ │ │ │ │ { │ │ │ │ "location": "types.html#inline_snapshot.Category", │ │ │ │ "text": "

See categories

", │ │ │ │ "title": "Category = Literal['update', 'fix', 'create', 'trim', 'fix-assert'] module-attribute" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "types.html#inline_snapshot.Snapshot", │ │ │ │ - "text": "

Can be used to annotate function arguments which accept snapshot values.

You can annotate function arguments with Snapshot[T] to declare that a snapshot-value can be passed as function argument. Snapshot[T] is a type alias for T, which allows you to pass int values instead of int snapshots.

Example:

from typing import Optional\nfrom inline_snapshot import snapshot, Snapshot\n\n# required snapshots\n\n\ndef check_in_bounds(value, lower: Snapshot[int], upper: Snapshot[int]):\n    assert lower <= value <= upper\n\n\ndef test_numbers():\n    for c in \"hello world\":\n        check_in_bounds(ord(c), snapshot(32), snapshot(119))\n\n    # use with normal values\n    check_in_bounds(5, 0, 10)\n\n\n# optional snapshots\n\n\ndef check_container(\n    value,\n    *,\n    value_repr: Optional[Snapshot[str]] = None,\n    length: Optional[Snapshot[int]] = None\n):\n    if value_repr is not None:\n        assert repr(value) == value_repr\n\n    if length is not None:\n        assert len(value) == length\n\n\ndef test_container():\n    check_container([1, 2], value_repr=snapshot(\"[1, 2]\"), length=snapshot(2))\n\n    check_container({1, 1}, length=snapshot(1))\n
Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/_types.py
class Snapshot(Protocol[T]):\n    \"\"\"Can be used to annotate function arguments which accept snapshot\n    values.\n\n    You can annotate function arguments with `Snapshot[T]` to declare that a snapshot-value can be passed as function argument.\n    `Snapshot[T]` is a type alias for `T`, which allows you to pass `int` values instead of `int` snapshots.\n\n\n    Example:\n    <!-- inline-snapshot: create fix trim first_block outcome-passed=2 -->\n    ``` python\n    from typing import Optional\n    from inline_snapshot import snapshot, Snapshot\n\n    # required snapshots\n\n\n    def check_in_bounds(value, lower: Snapshot[int], upper: Snapshot[int]):\n        assert lower <= value <= upper\n\n\n    def test_numbers():\n        for c in \"hello world\":\n            check_in_bounds(ord(c), snapshot(32), snapshot(119))\n\n        # use with normal values\n        check_in_bounds(5, 0, 10)\n\n\n    # optional snapshots\n\n\n    def check_container(\n        value,\n        *,\n        value_repr: Optional[Snapshot[str]] = None,\n        length: Optional[Snapshot[int]] = None\n    ):\n        if value_repr is not None:\n            assert repr(value) == value_repr\n\n        if length is not None:\n            assert len(value) == length\n\n\n    def test_container():\n        check_container([1, 2], value_repr=snapshot(\"[1, 2]\"), length=snapshot(2))\n\n        check_container({1, 1}, length=snapshot(1))\n    ```\n    \"\"\"\n\n    def __eq__(self, other: object, /) -> bool: ...  # pragma: no cover\n
", │ │ │ │ + "text": "

Can be used to annotate function arguments which accept snapshot values.

You can annotate function arguments with Snapshot[T] to declare that a snapshot-value can be passed as function argument. Snapshot[T] is a type alias for T, which allows you to pass int values instead of int snapshots.

Example:

from typing import Optional\nfrom inline_snapshot import snapshot, Snapshot\n\n# required snapshots\n\n\ndef check_in_bounds(value, lower: Snapshot[int], upper: Snapshot[int]):\n    assert lower <= value <= upper\n\n\ndef test_numbers():\n    for c in \"hello world\":\n        check_in_bounds(ord(c), snapshot(32), snapshot(119))\n\n    # use with normal values\n    check_in_bounds(5, 0, 10)\n\n\n# optional snapshots\n\n\ndef check_container(\n    value,\n    *,\n    value_repr: Optional[Snapshot[str]] = None,\n    length: Optional[Snapshot[int]] = None\n):\n    if value_repr is not None:\n        assert repr(value) == value_repr\n\n    if length is not None:\n        assert len(value) == length\n\n\ndef test_container():\n    check_container([1, 2], value_repr=snapshot(\"[1, 2]\"), length=snapshot(2))\n\n    check_container({1, 1}, length=snapshot(1))\n
Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/_types.py
class Snapshot(Protocol[T]):\n    \"\"\"Can be used to annotate function arguments which accept snapshot\n    values.\n\n    You can annotate function arguments with `Snapshot[T]` to declare that a snapshot-value can be passed as function argument.\n    `Snapshot[T]` is a type alias for `T`, which allows you to pass `int` values instead of `int` snapshots.\n\n\n    Example:\n    <!-- inline-snapshot: create fix trim first_block outcome-passed=2 -->\n    ``` python\n    from typing import Optional\n    from inline_snapshot import snapshot, Snapshot\n\n    # required snapshots\n\n\n    def check_in_bounds(value, lower: Snapshot[int], upper: Snapshot[int]):\n        assert lower <= value <= upper\n\n\n    def test_numbers():\n        for c in \"hello world\":\n            check_in_bounds(ord(c), snapshot(32), snapshot(119))\n\n        # use with normal values\n        check_in_bounds(5, 0, 10)\n\n\n    # optional snapshots\n\n\n    def check_container(\n        value,\n        *,\n        value_repr: Optional[Snapshot[str]] = None,\n        length: Optional[Snapshot[int]] = None\n    ):\n        if value_repr is not None:\n            assert repr(value) == value_repr\n\n        if length is not None:\n            assert len(value) == length\n\n\n    def test_container():\n        check_container([1, 2], value_repr=snapshot(\"[1, 2]\"), length=snapshot(2))\n\n        check_container({1, 1}, length=snapshot(1))\n    ```\n    \"\"\"\n\n    def __eq__(self, other: object, /) -> bool: ...  # pragma: no cover\n
", │ │ │ │ "title": "Snapshot" │ │ │ │ }, │ │ │ │ { │ │ │ │ "location": "external/external.html", │ │ │ │ "text": "

Storing snapshots in the source code is the main feature of inline snapshots. This has the advantage that you can easily see changes in code reviews. However, it also has some drawbacks:

  • It is problematic to snapshot a large amount of data, as it consumes significant space in your tests.
  • Binary data or images are not human-readable in your tests.

external() solves this problem and integrates nicely with inline snapshots. It stores a reference to the external data in a special external() object, which can be used like snapshot().

There are different storage protocols, such as hash or uuid, and different file formats, such as .txt, .bin, and .json. It is also possible to implement custom file formats.

Example:

from inline_snapshot import external\n\n\ndef test_something():\n    # inline-snapshot can determine the correct file types\n    assert \"string\" == external()\n    assert b\"bytes\" == external()\n\n    # Data structures with lists and dictionaries are stored as JSON\n    assert [\"json\", \"like\", \"data\"] == external()\n\n    # You can also explicitly specify the storage protocol\n    assert \"other text\" == external(\"uuid:\")\n\n    # And the format (.json instead of the default .txt in this case)\n    assert \"other text\" == external(\"uuid:.json\")\n

inline-snapshot will then fill in the missing parts when you create your snapshots. It will keep your specified protocols and file types and generate names for your snapshots.

from inline_snapshot import external\n\n\ndef test_something():\n    # inline-snapshot can determine the correct file types\n    assert \"string\" == external(\"uuid:e3e70682-c209-4cac-a29f-6fbed82c07cd.txt\")\n    assert b\"bytes\" == external(\"uuid:f728b4fa-4248-4e3a-8a5d-2f346baa9455.bin\")\n\n    # Data structures with lists and dictionaries are stored as JSON\n    assert [\"json\", \"like\", \"data\"] == external(\n        \"uuid:eb1167b3-67a9-4378-bc65-c1e582e2e662.json\"\n    )\n\n    # You can also explicitly specify the storage protocol\n    assert \"other text\" == external(\n        \"uuid:f7c1bd87-4da5-4709-9471-3d60c8a70639.txt\"\n    )\n\n    # And the format (.json instead of the default .txt in this case)\n    assert \"other text\" == external(\n        \"uuid:e443df78-9558-467f-9ba9-1faf7a024204.json\"\n    )\n

The external() function can also be used inside other data structures.

from inline_snapshot import snapshot, external\n\n\ndef test_something():\n    assert [\"long text\\n\" * times for times in [1, 2, 1000]] == snapshot(\n        [..., ..., external()]\n    )\n
from inline_snapshot import snapshot, external\n\n\ndef test_something():\n    assert [\"long text\\n\" * times for times in [1, 2, 1000]] == snapshot(\n        [\n            \"long text\\n\",\n            \"\"\"\\\nlong text\nlong text\n\"\"\",\n            external(\"uuid:e3e70682-c209-4cac-a29f-6fbed82c07cd.txt\"),\n        ]\n    )\n
", │ │ │ │ "title": "external()" │ │ │ │ }, │ │ ├── ./usr/share/doc/python-inline-snapshot-doc/html/types.html │ │ │ @@ -1658,15 +1658,15 @@ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ - Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/_types.py │ │ │ + Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/_types.py │ │ │
26
│ │ │  27
│ │ │  28
│ │ │  29
│ │ │  30
│ │ │  31
│ │ │  32
│ │ │ ├── html2text {}
│ │ │ │ @@ -101,15 +101,15 @@
│ │ │ │          assert len(value) == length
│ │ │ │  
│ │ │ │  
│ │ │ │  def test_container():
│ │ │ │      check_container([1, 2], value_repr=snapshot("[1, 2]"), length=snapshot(2))
│ │ │ │  
│ │ │ │      check_container({1, 1}, length=snapshot(1))
│ │ │ │ -Source code in cpython3_3.13_inline-snapshot/build/inline_snapshot/_types.py
│ │ │ │ +Source code in cpython3_3.14_inline-snapshot/build/inline_snapshot/_types.py
│ │ │ │     class Snapshot(Protocol[T]):
│ │ │ │  _2_6     """Can be used to annotate function arguments which accept snapshot
│ │ │ │  _2_7     values.
│ │ │ │  _2_8
│ │ │ │  _2_9     You can annotate function arguments with `Snapshot[T]` to declare that a
│ │ │ │  _3_0 snapshot-value can be passed as function argument.
│ │ │ │  _3_1     `Snapshot[T]` is a type alias for `T`, which allows you to pass `int`