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
│ │ │ │ ├── html2text {}
│ │ │ │ │ @@ -66,17 +66,17 @@
│ │ │ │ │ def test_something():
│ │ │ │ │ assert 1 == snapshot()
│ │ │ │ │ assert 2 <= snapshot(5)
│ │ │ │ │ [1;34m> pytest test_something.py --inline-snapshot=create,report
│ │ │ │ │ [0m[1m============================= test session starts
│ │ │ │ │ ==============================[0m
│ │ │ │ │ platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
│ │ │ │ │ -rootdir: /tmp/tmp.CETKrEZFtC
│ │ │ │ │ -plugins: pytest_freezer-0.4.8, hypothesis-6.122.1, typeguard-4.4.1, time-
│ │ │ │ │ -machine-2.14.1, subtests-0.13.1, inline-snapshot-0.14.0
│ │ │ │ │ +rootdir: /tmp/tmp.Wt1lijWNCQ
│ │ │ │ │ +plugins: hypothesis-6.122.1, typeguard-4.4.1, inline-snapshot-0.14.0, time-
│ │ │ │ │ +machine-2.14.1, subtests-0.13.1, pytest_freezer-0.4.8
│ │ │ │ │ collected 1 item
│ │ │ │ │
│ │ │ │ │ test_something.py [32m.[0m[32m
│ │ │ │ │ [100%][0m
│ │ │ │ │ =============================== inline snapshot
│ │ │ │ │ ================================
│ │ │ │ │ ─────────────────────────────── Create snapshots
│ │ │ │ │ @@ -124,25 +124,25 @@
│ │ │ │ │ +------------------------------------------------------------------------------
│ │ │ │ │ +
│ │ │ │ │ These changes are not applied.
│ │ │ │ │ Use --inline-snapshot=trim to apply them, or use the interactive mode with
│ │ │ │ │ --inline-snapshot=review
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │ -[32m============================== [32m[1m1 passed[0m[32m in 0.16s[0m[32m
│ │ │ │ │ +[32m============================== [32m[1m1 passed[0m[32m in 0.11s[0m[32m
│ │ │ │ │ ===============================[0m
│ │ │ │ │ ********** ----iinnlliinnee--ssnnaappsshhoott==sshhoorrtt--rreeppoorrtt_?¶ **********
│ │ │ │ │ give a short report over which changes can be made to the snapshots
│ │ │ │ │ [1;34m> pytest test_something.py --inline-snapshot=short-report
│ │ │ │ │ [0m[1m============================= test session starts
│ │ │ │ │ ==============================[0m
│ │ │ │ │ platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
│ │ │ │ │ -rootdir: /tmp/tmp.OH39pszdwB
│ │ │ │ │ -plugins: pytest_freezer-0.4.8, hypothesis-6.122.1, typeguard-4.4.1, time-
│ │ │ │ │ -machine-2.14.1, subtests-0.13.1, inline-snapshot-0.14.0
│ │ │ │ │ +rootdir: /tmp/tmp.78DgZaOzgR
│ │ │ │ │ +plugins: hypothesis-6.122.1, typeguard-4.4.1, inline-snapshot-0.14.0, time-
│ │ │ │ │ +machine-2.14.1, subtests-0.13.1, pytest_freezer-0.4.8
│ │ │ │ │ collected 1 item
│ │ │ │ │
│ │ │ │ │ test_something.py [32m.[0m[31mE[0m[31m
│ │ │ │ │ [100%][0m
│ │ │ │ │
│ │ │ │ │ ==================================== ERRORS
│ │ │ │ │ ====================================
│ │ │ │ │ @@ -156,28 +156,28 @@
│ │ │ │ │
│ │ │ │ │ You can also use --inline-snapshot=review to approve the changes interactively
│ │ │ │ │ [36m[1m=========================== short test summary info
│ │ │ │ │ ============================[0m
│ │ │ │ │ [31mERROR[0m test_something.py::[1mtest_something[0m - Failed: your snapshot
│ │ │ │ │ is missing one value.
│ │ │ │ │ [31m========================== [32m1 passed[0m, [31m[1m1 error[0m[31m in
│ │ │ │ │ -0.16s[0m[31m ==========================[0m
│ │ │ │ │ +0.13s[0m[31m ==========================[0m
│ │ │ │ │ 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
│ │ │ │ │ [1;34m> pytest test_something.py --inline-snapshot=report
│ │ │ │ │ [0m[1m============================= test session starts
│ │ │ │ │ ==============================[0m
│ │ │ │ │ platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
│ │ │ │ │ -rootdir: /tmp/tmp.uRkCyvpEg8
│ │ │ │ │ -plugins: pytest_freezer-0.4.8, hypothesis-6.122.1, typeguard-4.4.1, time-
│ │ │ │ │ -machine-2.14.1, subtests-0.13.1, inline-snapshot-0.14.0
│ │ │ │ │ +rootdir: /tmp/tmp.BAEOfeFGMp
│ │ │ │ │ +plugins: hypothesis-6.122.1, typeguard-4.4.1, inline-snapshot-0.14.0, time-
│ │ │ │ │ +machine-2.14.1, subtests-0.13.1, pytest_freezer-0.4.8
│ │ │ │ │ collected 1 item
│ │ │ │ │
│ │ │ │ │ test_something.py [32m.[0m[31mE[0m[31m
│ │ │ │ │ [100%][0m
│ │ │ │ │
│ │ │ │ │ ==================================== ERRORS
│ │ │ │ │ ====================================
│ │ │ │ │ @@ -237,24 +237,24 @@
│ │ │ │ │ --inline-snapshot=review
│ │ │ │ │
│ │ │ │ │ [36m[1m=========================== short test summary info
│ │ │ │ │ ============================[0m
│ │ │ │ │ [31mERROR[0m test_something.py::[1mtest_something[0m - Failed: your snapshot
│ │ │ │ │ is missing one value.
│ │ │ │ │ [31m========================== [32m1 passed[0m, [31m[1m1 error[0m[31m in
│ │ │ │ │ -0.18s[0m[31m ==========================[0m
│ │ │ │ │ +0.21s[0m[31m ==========================[0m
│ │ │ │ │ ********** ----iinnlliinnee--ssnnaappsshhoott==rreevviieeww_?¶ **********
│ │ │ │ │ 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[1m============================= test session starts
│ │ │ │ │ ==============================[0m
│ │ │ │ │ platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
│ │ │ │ │ -rootdir: /tmp/tmp.hpELK540k1
│ │ │ │ │ -plugins: pytest_freezer-0.4.8, hypothesis-6.122.1, typeguard-4.4.1, time-
│ │ │ │ │ -machine-2.14.1, subtests-0.13.1, inline-snapshot-0.14.0
│ │ │ │ │ +rootdir: /tmp/tmp.y5TdogDd7R
│ │ │ │ │ +plugins: hypothesis-6.122.1, typeguard-4.4.1, inline-snapshot-0.14.0, time-
│ │ │ │ │ +machine-2.14.1, subtests-0.13.1, pytest_freezer-0.4.8
│ │ │ │ │ collected 1 item
│ │ │ │ │
│ │ │ │ │ test_something.py [32m.[0m[32m
│ │ │ │ │ [100%][0m
│ │ │ │ │ =============================== inline snapshot
│ │ │ │ │ ================================
│ │ │ │ │ ─────────────────────────────── Create snapshots
│ │ │ │ │ @@ -298,15 +298,15 @@
│ │ │ │ │ |
│ │ │ │ │ | + assert 2 <= snapshot(2)
│ │ │ │ │ |
│ │ │ │ │ +------------------------------------------------------------------------------
│ │ │ │ │ +
│ │ │ │ │ do you want to trim these snapshots? [y/n] (n):
│ │ │ │ │
│ │ │ │ │ -[32m============================== [32m[1m1 passed[0m[32m in 0.23s[0m[32m
│ │ │ │ │ +[32m============================== [32m[1m1 passed[0m[32m in 0.19s[0m[32m
│ │ │ │ │ ===============================[0m
│ │ │ │ │ ********** ----iinnlliinnee--ssnnaappsshhoott==ddiissaabbllee_?¶ **********
│ │ │ │ │ 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
│ │ │ ├── ./usr/share/doc/python-inline-snapshot-doc/html/search/search_index.json
│ │ │ │ ├── Pretty-printed
│ │ │ │ │┄ Similarity: 0.9965277777777778%
│ │ │ │ │┄ Differences: {"'docs'": "{106: {'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 which is compared to the '
│ │ │ │ │┄ "recorded output
\\'\\'
stderr
Snapshot[str]
"
│ │ │ │ │┄ "
The following functions are build on top of inline-snapshot and could also be implemented in an extra library.
They are part of inline-snapshot because they are general useful and do not depend on other libraries.
",
│ │ │ │ │ "title": "
inline_snapshot.extra
"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "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 which is compared to the recorded output
''
stderr
Snapshot[str]
snapshot which 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
.pybuild/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 which is compared to the recorded output\n stderr: snapshot which 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 -->\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 which is compared to the recorded output
''
stderr
Snapshot[str]
snapshot which 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
.pybuild/cpython3_3.12_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 which is compared to the recorded output\n stderr: snapshot which 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 -->\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 which is compared with f\"{type}: {message}\"
if an exception occured or \"<no exception>\"
if no exception was 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
.pybuild/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 which is compared with `#!python f\"{type}: {message}\"` if an exception occured or `#!python \"<no exception>\"` if no exception was 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 -->\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 which is compared with f\"{type}: {message}\"
if an exception occured or \"<no exception>\"
if no exception was 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
.pybuild/cpython3_3.12_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 which is compared with `#!python f\"{type}: {message}\"` if an exception occured or `#!python \"<no exception>\"` if no exception was 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 -->\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": "getitem_snapshot.html",
│ │ │ │ │ "text": "",
│ │ │ │ │ "title": "snapshot()[key]"
│ │ │ │ │ },
│ │ │ │ │ @@ -612,65 +612,65 @@
│ │ │ │ │ {
│ │ │ │ │ "location": "outsource.html#api",
│ │ │ │ │ "text": "",
│ │ │ │ │ "title": "API"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "location": "outsource.html#inline_snapshot.outsource",
│ │ │ │ │ - "text": "
Outsource some data into an external file.
>>> png_data = b\"some_bytes\" # should be the replaced with your actual data\n>>> outsource(png_data, suffix=\".png\")\nexternal(\"212974ed1835*.png\")\n
Parameters:
Name Type Description Default
data
Union[str, bytes]
data which should be outsourced. strings are encoded with \"utf-8\"
.
required
suffix
Optional[str]
overwrite file suffix. The default is \".bin\"
if data is an instance of bytes
and \".txt\"
for str
.
None
Returns:
Type Description
external
The external data.
Source code in
.pybuild/cpython3_3.13_inline-snapshot/build/inline_snapshot/_external.py
def outsource(data: Union[str, bytes], *, suffix: Optional[str] = None) -> external:\n \"\"\"Outsource some data into an external file.\n\n ``` pycon\n >>> png_data = b\"some_bytes\" # should be the replaced with your actual data\n >>> outsource(png_data, suffix=\".png\")\n external(\"212974ed1835*.png\")\n\n ```\n\n Parameters:\n data: data which should be outsourced. strings are encoded with `\"utf-8\"`.\n\n suffix: overwrite file suffix. The default is `\".bin\"` if data is an instance of `#!python bytes` and `\".txt\"` for `#!python str`.\n\n Returns:\n The external data.\n \"\"\"\n if isinstance(data, str):\n data = data.encode(\"utf-8\")\n if suffix is None:\n suffix = \".txt\"\n\n elif isinstance(data, bytes):\n if suffix is None:\n suffix = \".bin\"\n else:\n raise TypeError(\"data has to be of type bytes | str\")\n\n if not suffix or suffix[0] != \".\":\n raise ValueError(\"suffix has to start with a '.' like '.png'\")\n\n m = hashlib.sha256()\n m.update(data)\n hash = m.hexdigest()\n\n assert storage is not None\n\n name = hash + suffix\n\n if not storage.lookup_all(name):\n path = hash + \"-new\" + suffix\n storage.save(path, data)\n\n return external(name)\n
",
│ │ │ │ │ + "text": "
Outsource some data into an external file.
>>> png_data = b\"some_bytes\" # should be the replaced with your actual data\n>>> outsource(png_data, suffix=\".png\")\nexternal(\"212974ed1835*.png\")\n
Parameters:
Name Type Description Default
data
Union[str, bytes]
data which should be outsourced. strings are encoded with \"utf-8\"
.
required
suffix
Optional[str]
overwrite file suffix. The default is \".bin\"
if data is an instance of bytes
and \".txt\"
for str
.
None
Returns:
Type Description
external
The external data.
Source code in
.pybuild/cpython3_3.12_inline-snapshot/build/inline_snapshot/_external.py
def outsource(data: Union[str, bytes], *, suffix: Optional[str] = None) -> external:\n \"\"\"Outsource some data into an external file.\n\n ``` pycon\n >>> png_data = b\"some_bytes\" # should be the replaced with your actual data\n >>> outsource(png_data, suffix=\".png\")\n external(\"212974ed1835*.png\")\n\n ```\n\n Parameters:\n data: data which should be outsourced. strings are encoded with `\"utf-8\"`.\n\n suffix: overwrite file suffix. The default is `\".bin\"` if data is an instance of `#!python bytes` and `\".txt\"` for `#!python str`.\n\n Returns:\n The external data.\n \"\"\"\n if isinstance(data, str):\n data = data.encode(\"utf-8\")\n if suffix is None:\n suffix = \".txt\"\n\n elif isinstance(data, bytes):\n if suffix is None:\n suffix = \".bin\"\n else:\n raise TypeError(\"data has to be of type bytes | str\")\n\n if not suffix or suffix[0] != \".\":\n raise ValueError(\"suffix has to start with a '.' like '.png'\")\n\n m = hashlib.sha256()\n m.update(data)\n hash = m.hexdigest()\n\n assert storage is not None\n\n name = hash + suffix\n\n if not storage.lookup_all(name):\n path = hash + \"-new\" + suffix\n storage.save(path, data)\n\n return external(name)\n
",
│ │ │ │ │ "title": "
inline_snapshot.outsource(data, *, suffix=None)
"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "location": "outsource.html#inline_snapshot.external",
│ │ │ │ │ - "text": "Source code in
.pybuild/cpython3_3.13_inline-snapshot/build/inline_snapshot/_external.py
class external:\n def __init__(self, name: str):\n \"\"\"External objects are used as a representation for outsourced data.\n You should not create them directly.\n\n The external data is stored inside `<pytest_config_dir>/.inline_snapshot/external`,\n where `<pytest_config_dir>` is replaced by the directory containing the Pytest configuration file, if any.\n Data which is outsourced but not referenced in the source code jet has a '-new' suffix in the filename.\n\n Parameters:\n name: the name of the external stored object.\n \"\"\"\n\n m = re.fullmatch(r\"([0-9a-fA-F]*)\\*?(\\.[a-zA-Z0-9]*)\", name)\n\n if m:\n self._hash, self._suffix = m.groups()\n else:\n raise ValueError(\n \"path has to be of the form <hash>.<suffix> or <partial_hash>*.<suffix>\"\n )\n\n @property\n def _path(self):\n return f\"{self._hash}*{self._suffix}\"\n\n def __repr__(self):\n \"\"\"Returns the representation of the external object.\n\n The length of the hash can be specified in the\n [config](configuration.md).\n \"\"\"\n hash = self._hash[: _config.config.hash_length]\n\n if len(hash) == 64:\n return f'external(\"{hash}{self._suffix}\")'\n else:\n return f'external(\"{hash}*{self._suffix}\")'\n\n def __eq__(self, other):\n \"\"\"Two external objects are equal if they have the same hash and\n suffix.\"\"\"\n if not isinstance(other, external):\n return NotImplemented\n\n min_hash_len = min(len(self._hash), len(other._hash))\n\n if self._hash[:min_hash_len] != other._hash[:min_hash_len]:\n return False\n\n if self._suffix != other._suffix:\n return False\n\n return True\n\n def _load_value(self):\n assert storage is not None\n return storage.read(self._path)\n
",
│ │ │ │ │ + "text": "Source code in
.pybuild/cpython3_3.12_inline-snapshot/build/inline_snapshot/_external.py
class external:\n def __init__(self, name: str):\n \"\"\"External objects are used as a representation for outsourced data.\n You should not create them directly.\n\n The external data is stored inside `<pytest_config_dir>/.inline_snapshot/external`,\n where `<pytest_config_dir>` is replaced by the directory containing the Pytest configuration file, if any.\n Data which is outsourced but not referenced in the source code jet has a '-new' suffix in the filename.\n\n Parameters:\n name: the name of the external stored object.\n \"\"\"\n\n m = re.fullmatch(r\"([0-9a-fA-F]*)\\*?(\\.[a-zA-Z0-9]*)\", name)\n\n if m:\n self._hash, self._suffix = m.groups()\n else:\n raise ValueError(\n \"path has to be of the form <hash>.<suffix> or <partial_hash>*.<suffix>\"\n )\n\n @property\n def _path(self):\n return f\"{self._hash}*{self._suffix}\"\n\n def __repr__(self):\n \"\"\"Returns the representation of the external object.\n\n The length of the hash can be specified in the\n [config](configuration.md).\n \"\"\"\n hash = self._hash[: _config.config.hash_length]\n\n if len(hash) == 64:\n return f'external(\"{hash}{self._suffix}\")'\n else:\n return f'external(\"{hash}*{self._suffix}\")'\n\n def __eq__(self, other):\n \"\"\"Two external objects are equal if they have the same hash and\n suffix.\"\"\"\n if not isinstance(other, external):\n return NotImplemented\n\n min_hash_len = min(len(self._hash), len(other._hash))\n\n if self._hash[:min_hash_len] != other._hash[:min_hash_len]:\n return False\n\n if self._suffix != other._suffix:\n return False\n\n return True\n\n def _load_value(self):\n assert storage is not None\n return storage.read(self._path)\n
",
│ │ │ │ │ "title": "
inline_snapshot.external
"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "location": "outsource.html#inline_snapshot.external.__eq__",
│ │ │ │ │ - "text": "
Two external objects are equal if they have the same hash and suffix.
Source code in
.pybuild/cpython3_3.13_inline-snapshot/build/inline_snapshot/_external.py
def __eq__(self, other):\n \"\"\"Two external objects are equal if they have the same hash and\n suffix.\"\"\"\n if not isinstance(other, external):\n return NotImplemented\n\n min_hash_len = min(len(self._hash), len(other._hash))\n\n if self._hash[:min_hash_len] != other._hash[:min_hash_len]:\n return False\n\n if self._suffix != other._suffix:\n return False\n\n return True\n
",
│ │ │ │ │ + "text": "
Two external objects are equal if they have the same hash and suffix.
Source code in
.pybuild/cpython3_3.12_inline-snapshot/build/inline_snapshot/_external.py
def __eq__(self, other):\n \"\"\"Two external objects are equal if they have the same hash and\n suffix.\"\"\"\n if not isinstance(other, external):\n return NotImplemented\n\n min_hash_len = min(len(self._hash), len(other._hash))\n\n if self._hash[:min_hash_len] != other._hash[:min_hash_len]:\n return False\n\n if self._suffix != other._suffix:\n return False\n\n return True\n
",
│ │ │ │ │ "title": "
__eq__(other)
"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "location": "outsource.html#inline_snapshot.external.__init__",
│ │ │ │ │ - "text": "
External objects are used as a representation for outsourced data. You should not create them directly.
The external data is stored inside <pytest_config_dir>/.inline_snapshot/external
, where <pytest_config_dir>
is replaced by the directory containing the Pytest configuration file, if any. Data which is outsourced but not referenced in the source code jet has a '-new' suffix in the filename.
Parameters:
Name Type Description Default
name
str
the name of the external stored object.
required Source code in
.pybuild/cpython3_3.13_inline-snapshot/build/inline_snapshot/_external.py
def __init__(self, name: str):\n \"\"\"External objects are used as a representation for outsourced data.\n You should not create them directly.\n\n The external data is stored inside `<pytest_config_dir>/.inline_snapshot/external`,\n where `<pytest_config_dir>` is replaced by the directory containing the Pytest configuration file, if any.\n Data which is outsourced but not referenced in the source code jet has a '-new' suffix in the filename.\n\n Parameters:\n name: the name of the external stored object.\n \"\"\"\n\n m = re.fullmatch(r\"([0-9a-fA-F]*)\\*?(\\.[a-zA-Z0-9]*)\", name)\n\n if m:\n self._hash, self._suffix = m.groups()\n else:\n raise ValueError(\n \"path has to be of the form <hash>.<suffix> or <partial_hash>*.<suffix>\"\n )\n
",
│ │ │ │ │ + "text": "
External objects are used as a representation for outsourced data. You should not create them directly.
The external data is stored inside <pytest_config_dir>/.inline_snapshot/external
, where <pytest_config_dir>
is replaced by the directory containing the Pytest configuration file, if any. Data which is outsourced but not referenced in the source code jet has a '-new' suffix in the filename.
Parameters:
Name Type Description Default
name
str
the name of the external stored object.
required Source code in
.pybuild/cpython3_3.12_inline-snapshot/build/inline_snapshot/_external.py
def __init__(self, name: str):\n \"\"\"External objects are used as a representation for outsourced data.\n You should not create them directly.\n\n The external data is stored inside `<pytest_config_dir>/.inline_snapshot/external`,\n where `<pytest_config_dir>` is replaced by the directory containing the Pytest configuration file, if any.\n Data which is outsourced but not referenced in the source code jet has a '-new' suffix in the filename.\n\n Parameters:\n name: the name of the external stored object.\n \"\"\"\n\n m = re.fullmatch(r\"([0-9a-fA-F]*)\\*?(\\.[a-zA-Z0-9]*)\", name)\n\n if m:\n self._hash, self._suffix = m.groups()\n else:\n raise ValueError(\n \"path has to be of the form <hash>.<suffix> or <partial_hash>*.<suffix>\"\n )\n
",
│ │ │ │ │ "title": "
__init__(name)
"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "location": "outsource.html#inline_snapshot.external.__repr__",
│ │ │ │ │ - "text": "
Returns the representation of the external object.
The length of the hash can be specified in the config.
Source code in
.pybuild/cpython3_3.13_inline-snapshot/build/inline_snapshot/_external.py
def __repr__(self):\n \"\"\"Returns the representation of the external object.\n\n The length of the hash can be specified in the\n [config](configuration.md).\n \"\"\"\n hash = self._hash[: _config.config.hash_length]\n\n if len(hash) == 64:\n return f'external(\"{hash}{self._suffix}\")'\n else:\n return f'external(\"{hash}*{self._suffix}\")'\n
",
│ │ │ │ │ + "text": "
Returns the representation of the external object.
The length of the hash can be specified in the config.
Source code in
.pybuild/cpython3_3.12_inline-snapshot/build/inline_snapshot/_external.py
def __repr__(self):\n \"\"\"Returns the representation of the external object.\n\n The length of the hash can be specified in the\n [config](configuration.md).\n \"\"\"\n hash = self._hash[: _config.config.hash_length]\n\n if len(hash) == 64:\n return f'external(\"{hash}{self._suffix}\")'\n else:\n return f'external(\"{hash}*{self._suffix}\")'\n
",
│ │ │ │ │ "title": "
__repr__()
"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "location": "outsource.html#pytest-options",
│ │ │ │ │ "text": "
It interacts with the following --inline-snapshot
flags:
trim
removes every snapshots form the storage which is not referenced with external(...)
in the code.
",
│ │ │ │ │ "title": "pytest options"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "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 integration"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "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
\u001b[1;34m> pytest test_something.py --inline-snapshot=create,report\n\u001b[0m\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0\nrootdir: /tmp/tmp.CETKrEZFtC\nplugins: pytest_freezer-0.4.8, hypothesis-6.122.1, typeguard-4.4.1, time-machine-2.14.1, subtests-0.13.1, inline-snapshot-0.14.0\ncollected 1 item\n\ntest_something.py \u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n=============================== inline snapshot ================================\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Create snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -2,5 +2,5 @@ |\n| |\n| |\n| |\n| def test_something(): |\n| - assert 1 == snapshot() |\n| + assert 1 == snapshot(1) |\n| assert 2 <= snapshot(5) |\n+------------------------------------------------------------------------------+\nThese changes will be applied, because you used --inline-snapshot=create\n\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Trim snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -3,4 +3,4 @@ |\n| |\n| |\n| def test_something(): |\n| assert 1 == snapshot(1) |\n| - assert 2 <= snapshot(5) |\n| + assert 2 <= snapshot(2) |\n+------------------------------------------------------------------------------+\nThese changes are not applied.\nUse --inline-snapshot=trim to apply them, or use the interactive mode with \n--inline-snapshot=review\n\n\n\u001b[32m============================== \u001b[32m\u001b[1m1 passed\u001b[0m\u001b[32m in 0.16s\u001b[0m\u001b[32m ===============================\u001b[0m\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
\u001b[1;34m> pytest test_something.py --inline-snapshot=create,report\n\u001b[0m\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0\nrootdir: /tmp/tmp.Wt1lijWNCQ\nplugins: hypothesis-6.122.1, typeguard-4.4.1, inline-snapshot-0.14.0, time-machine-2.14.1, subtests-0.13.1, pytest_freezer-0.4.8\ncollected 1 item\n\ntest_something.py \u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n=============================== inline snapshot ================================\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Create snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -2,5 +2,5 @@ |\n| |\n| |\n| |\n| def test_something(): |\n| - assert 1 == snapshot() |\n| + assert 1 == snapshot(1) |\n| assert 2 <= snapshot(5) |\n+------------------------------------------------------------------------------+\nThese changes will be applied, because you used --inline-snapshot=create\n\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Trim snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -3,4 +3,4 @@ |\n| |\n| |\n| def test_something(): |\n| assert 1 == snapshot(1) |\n| - assert 2 <= snapshot(5) |\n| + assert 2 <= snapshot(2) |\n+------------------------------------------------------------------------------+\nThese changes are not applied.\nUse --inline-snapshot=trim to apply them, or use the interactive mode with \n--inline-snapshot=review\n\n\n\u001b[32m============================== \u001b[32m\u001b[1m1 passed\u001b[0m\u001b[32m in 0.11s\u001b[0m\u001b[32m ===============================\u001b[0m\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
\u001b[1;34m> pytest test_something.py --inline-snapshot=short-report\n\u001b[0m\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0\nrootdir: /tmp/tmp.OH39pszdwB\nplugins: pytest_freezer-0.4.8, hypothesis-6.122.1, typeguard-4.4.1, time-machine-2.14.1, subtests-0.13.1, inline-snapshot-0.14.0\ncollected 1 item\n\ntest_something.py \u001b[32m.\u001b[0m\u001b[31mE\u001b[0m\u001b[31m [100%]\u001b[0m\n\n==================================== ERRORS ====================================\n\u001b[31m\u001b[1m_____________________ ERROR at teardown of test_something ______________________\u001b[0m\n\u001b[0myour snapshot \u001b[95mis\u001b[39;49;00m missing one value.\u001b[90m\u001b[39;49;00m\n=============================== inline snapshot ================================\nInfo: one snapshot can be trimmed (--inline-snapshot=trim)\nError: one snapshot is missing a value (--inline-snapshot=create)\n\nYou can also use --inline-snapshot=review to approve the changes interactively\n\u001b[36m\u001b[1m=========================== short test summary info ============================\u001b[0m\n\u001b[31mERROR\u001b[0m test_something.py::\u001b[1mtest_something\u001b[0m - Failed: your snapshot is missing one value.\n\u001b[31m========================== \u001b[32m1 passed\u001b[0m, \u001b[31m\u001b[1m1 error\u001b[0m\u001b[31m in 0.16s\u001b[0m\u001b[31m ==========================\u001b[0m\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
\u001b[1;34m> pytest test_something.py --inline-snapshot=short-report\n\u001b[0m\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0\nrootdir: /tmp/tmp.78DgZaOzgR\nplugins: hypothesis-6.122.1, typeguard-4.4.1, inline-snapshot-0.14.0, time-machine-2.14.1, subtests-0.13.1, pytest_freezer-0.4.8\ncollected 1 item\n\ntest_something.py \u001b[32m.\u001b[0m\u001b[31mE\u001b[0m\u001b[31m [100%]\u001b[0m\n\n==================================== ERRORS ====================================\n\u001b[31m\u001b[1m_____________________ ERROR at teardown of test_something ______________________\u001b[0m\n\u001b[0myour snapshot \u001b[95mis\u001b[39;49;00m missing one value.\u001b[90m\u001b[39;49;00m\n=============================== inline snapshot ================================\nInfo: one snapshot can be trimmed (--inline-snapshot=trim)\nError: one snapshot is missing a value (--inline-snapshot=create)\n\nYou can also use --inline-snapshot=review to approve the changes interactively\n\u001b[36m\u001b[1m=========================== short test summary info ============================\u001b[0m\n\u001b[31mERROR\u001b[0m test_something.py::\u001b[1mtest_something\u001b[0m - Failed: your snapshot is missing one value.\n\u001b[31m========================== \u001b[32m1 passed\u001b[0m, \u001b[31m\u001b[1m1 error\u001b[0m\u001b[31m in 0.13s\u001b[0m\u001b[31m ==========================\u001b[0m\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
\u001b[1;34m> pytest test_something.py --inline-snapshot=report\n\u001b[0m\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0\nrootdir: /tmp/tmp.uRkCyvpEg8\nplugins: pytest_freezer-0.4.8, hypothesis-6.122.1, typeguard-4.4.1, time-machine-2.14.1, subtests-0.13.1, inline-snapshot-0.14.0\ncollected 1 item\n\ntest_something.py \u001b[32m.\u001b[0m\u001b[31mE\u001b[0m\u001b[31m [100%]\u001b[0m\n\n==================================== ERRORS ====================================\n\u001b[31m\u001b[1m_____________________ ERROR at teardown of test_something ______________________\u001b[0m\n\u001b[0myour snapshot \u001b[95mis\u001b[39;49;00m missing one value.\u001b[90m\u001b[39;49;00m\n=============================== inline snapshot ================================\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Create snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -2,5 +2,5 @@ |\n| |\n| |\n| |\n| def test_something(): |\n| - assert 1 == snapshot() |\n| + assert 1 == snapshot(1) |\n| assert 2 <= snapshot(5) |\n+------------------------------------------------------------------------------+\nThese changes are not applied.\nUse --inline-snapshot=create to apply them, or use the interactive mode with \n--inline-snapshot=review\n\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Trim snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -3,4 +3,4 @@ |\n| |\n| |\n| def test_something(): |\n| assert 1 == snapshot() |\n| - assert 2 <= snapshot(5) |\n| + assert 2 <= snapshot(2) |\n+------------------------------------------------------------------------------+\nThese changes are not applied.\nUse --inline-snapshot=trim to apply them, or use the interactive mode with \n--inline-snapshot=review\n\n\u001b[36m\u001b[1m=========================== short test summary info ============================\u001b[0m\n\u001b[31mERROR\u001b[0m test_something.py::\u001b[1mtest_something\u001b[0m - Failed: your snapshot is missing one value.\n\u001b[31m========================== \u001b[32m1 passed\u001b[0m, \u001b[31m\u001b[1m1 error\u001b[0m\u001b[31m in 0.18s\u001b[0m\u001b[31m ==========================\u001b[0m\n
",
│ │ │ │ │ + "text": "
Shows a diff report over which changes can be made to the snapshots
\u001b[1;34m> pytest test_something.py --inline-snapshot=report\n\u001b[0m\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0\nrootdir: /tmp/tmp.BAEOfeFGMp\nplugins: hypothesis-6.122.1, typeguard-4.4.1, inline-snapshot-0.14.0, time-machine-2.14.1, subtests-0.13.1, pytest_freezer-0.4.8\ncollected 1 item\n\ntest_something.py \u001b[32m.\u001b[0m\u001b[31mE\u001b[0m\u001b[31m [100%]\u001b[0m\n\n==================================== ERRORS ====================================\n\u001b[31m\u001b[1m_____________________ ERROR at teardown of test_something ______________________\u001b[0m\n\u001b[0myour snapshot \u001b[95mis\u001b[39;49;00m missing one value.\u001b[90m\u001b[39;49;00m\n=============================== inline snapshot ================================\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Create snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -2,5 +2,5 @@ |\n| |\n| |\n| |\n| def test_something(): |\n| - assert 1 == snapshot() |\n| + assert 1 == snapshot(1) |\n| assert 2 <= snapshot(5) |\n+------------------------------------------------------------------------------+\nThese changes are not applied.\nUse --inline-snapshot=create to apply them, or use the interactive mode with \n--inline-snapshot=review\n\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Trim snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -3,4 +3,4 @@ |\n| |\n| |\n| def test_something(): |\n| assert 1 == snapshot() |\n| - assert 2 <= snapshot(5) |\n| + assert 2 <= snapshot(2) |\n+------------------------------------------------------------------------------+\nThese changes are not applied.\nUse --inline-snapshot=trim to apply them, or use the interactive mode with \n--inline-snapshot=review\n\n\u001b[36m\u001b[1m=========================== short test summary info ============================\u001b[0m\n\u001b[31mERROR\u001b[0m test_something.py::\u001b[1mtest_something\u001b[0m - Failed: your snapshot is missing one value.\n\u001b[31m========================== \u001b[32m1 passed\u001b[0m, \u001b[31m\u001b[1m1 error\u001b[0m\u001b[31m in 0.21s\u001b[0m\u001b[31m ==========================\u001b[0m\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
\u001b[1;34m> pytest test_something.py --inline-snapshot=review\n\u001b[0m\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0\nrootdir: /tmp/tmp.hpELK540k1\nplugins: pytest_freezer-0.4.8, hypothesis-6.122.1, typeguard-4.4.1, time-machine-2.14.1, subtests-0.13.1, inline-snapshot-0.14.0\ncollected 1 item\n\ntest_something.py \u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n=============================== inline snapshot ================================\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Create snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -2,5 +2,5 @@ |\n| |\n| |\n| |\n| def test_something(): |\n| - assert 1 == snapshot() |\n| + assert 1 == snapshot(1) |\n| assert 2 <= snapshot(5) |\n+------------------------------------------------------------------------------+\ndo you want to create these snapshots? [y/n] (n): \n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Trim snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -3,4 +3,4 @@ |\n| |\n| |\n| def test_something(): |\n| assert 1 == snapshot(1) |\n| - assert 2 <= snapshot(5) |\n| + assert 2 <= snapshot(2) |\n+------------------------------------------------------------------------------+\ndo you want to trim these snapshots? [y/n] (n): \n\n\u001b[32m============================== \u001b[32m\u001b[1m1 passed\u001b[0m\u001b[32m in 0.23s\u001b[0m\u001b[32m ===============================\u001b[0m\n
",
│ │ │ │ │ + "text": "
Shows a diff report for each category and ask if you want to apply the changes
\u001b[1;34m> pytest test_something.py --inline-snapshot=review\n\u001b[0m\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0\nrootdir: /tmp/tmp.y5TdogDd7R\nplugins: hypothesis-6.122.1, typeguard-4.4.1, inline-snapshot-0.14.0, time-machine-2.14.1, subtests-0.13.1, pytest_freezer-0.4.8\ncollected 1 item\n\ntest_something.py \u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n=============================== inline snapshot ================================\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Create snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -2,5 +2,5 @@ |\n| |\n| |\n| |\n| def test_something(): |\n| - assert 1 == snapshot() |\n| + assert 1 == snapshot(1) |\n| assert 2 <= snapshot(5) |\n+------------------------------------------------------------------------------+\ndo you want to create these snapshots? [y/n] (n): \n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Trim snapshots \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n+----------------------------- test_something.py ------------------------------+\n| @@ -3,4 +3,4 @@ |\n| |\n| |\n| def test_something(): |\n| assert 1 == snapshot(1) |\n| - assert 2 <= snapshot(5) |\n| + assert 2 <= snapshot(2) |\n+------------------------------------------------------------------------------+\ndo you want to trim these snapshots? [y/n] (n): \n\n\u001b[32m============================== \u001b[32m\u001b[1m1 passed\u001b[0m\u001b[32m in 0.19s\u001b[0m\u001b[32m ===============================\u001b[0m\n
",
│ │ │ │ │ "title": "--inline-snapshot=review"
│ │ │ │ │ },
│ │ │ │ │ {
│ │ │ │ │ "location": "pytest.html#-inline-snapshotdisable",
│ │ │ │ │ "text": "
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
",
│ │ │ │ │ "title": "--inline-snapshot=disable"
│ │ │ │ │ },
│ │ │ │ │ @@ -722,12 +722,12 @@
│ │ │ │ │ {
│ │ │ │ │ "location": "types.html#inline_snapshot.Category",
│ │ │ │ │ "text": "
See categories
",
│ │ │ │ │ "title": "
Category = Literal['update', 'fix', 'create', 'trim']
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
.pybuild/cpython3_3.13_inline-snapshot/build/inline_snapshot/_types.py
class Snapshot(Generic[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
",
│ │ │ │ │ + "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
.pybuild/cpython3_3.12_inline-snapshot/build/inline_snapshot/_types.py
class Snapshot(Generic[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
",
│ │ │ │ │ "title": "
Snapshot
"
│ │ │ │ │ }
│ │ │ │ │ ]
│ │ │ │ │ }
│ │ │ ├── ./usr/share/doc/python-inline-snapshot-doc/html/types.html
│ │ │ │ @@ -1001,15 +1001,15 @@
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │ - Source code in .pybuild/cpython3_3.13_inline-snapshot/build/inline_snapshot/_types.py
│ │ │ │ + Source code in .pybuild/cpython3_3.12_inline-snapshot/build/inline_snapshot/_types.py
│ │ │ │ 21
│ │ │ │ 22
│ │ │ │ 23
│ │ │ │ 24
│ │ │ │ 25
│ │ │ │ 26
│ │ │ │ 27
│ │ │ │ ├── html2text {}
│ │ │ │ │ @@ -78,15 +78,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 .pybuild/cpython3_3.13_inline-snapshot/build/inline_snapshot/
│ │ │ │ │ +Source code in .pybuild/cpython3_3.12_inline-snapshot/build/inline_snapshot/
│ │ │ │ │ _types.py
│ │ │ │ │ class Snapshot(Generic[T]):
│ │ │ │ │ _2_1 """Can be used to annotate function arguments which accept snapshot
│ │ │ │ │ _2_2 values.
│ │ │ │ │ _2_3
│ │ │ │ │ _2_4 You can annotate function arguments with `Snapshot[T]` to declare that a
│ │ │ │ │ _2_5 snapshot-value can be passed as function argument.
|