inline-snapshot


Nameinline-snapshot JSON
Version 0.24.0 PyPI version JSON
download
home_pageNone
Summarygolden master/snapshot/approval testing library which puts the values right into your source code
upload_time2025-07-15 03:41:29
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- -8<- [start:Header] -->

<p align="center">
  <a href="https://15r10nk.github.io/inline-snapshot/latest/">
    <img src="docs/assets/logo.svg" width="500" alt="inline-snapshot">
  </a>
</p>

![ci](https://github.com/15r10nk/inline-snapshot/actions/workflows/ci.yml/badge.svg?branch=main)
[![Docs](https://img.shields.io/badge/docs-mkdocs-green)](https://15r10nk.github.io/inline-snapshot/latest/)
[![pypi version](https://img.shields.io/pypi/v/inline-snapshot.svg)](https://pypi.org/project/inline-snapshot/)
![Python Versions](https://img.shields.io/pypi/pyversions/inline-snapshot)
[![PyPI - Downloads](https://img.shields.io/pypi/dw/inline-snapshot)](https://pypacktrends.com/?packages=inline-snapshot&time_range=2years)
[![coverage](https://img.shields.io/badge/coverage-100%25-blue)](https://15r10nk.github.io/inline-snapshot/latest/contributing/#coverage)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/15r10nk)](https://github.com/sponsors/15r10nk)

<!-- -8<- [end:Header] -->

## Installation

You can install "inline-snapshot" via [pip](https://pypi.org/project/pip/):

``` bash
pip install inline-snapshot
```

> [!IMPORTANT]
> Hello, I would like to inform you about some changes. I have started to offer [insider](https://15r10nk.github.io/inline-snapshot/latest/insiders/) features for inline-snapshot. I will only release features as insider features if they will not cause problems for you when used in an open source project.
> I hope sponsoring will allow me to spend more time working on open source projects.
> Thank you for using inline-snapshot, the future will be 🚀.

## Key Features

- **support for normal assertions:** inline-snapshot can now also fix normal assertions which do not use `snapshot()` like:

    ``` python
    assert 1 + 1 == 3
    ```

    You can learn [here](fix_assert.md) more about this feature.


- **Intuitive Semantics:** `snapshot(x)` mirrors `x` for easy understanding.
- **Versatile Comparison Support:** Equipped with
    [`x == snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/),
    [`x <= snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/cmp_snapshot/),
    [`x in snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/in_snapshot/), and
    [`snapshot(...)[key]`](https://15r10nk.github.io/inline-snapshot/latest/getitem_snapshot/).
- **Enhanced Control Flags:** Utilize various [flags](https://15r10nk.github.io/inline-snapshot/latest/pytest/) for precise control of which snapshots you want to change.
- **Preserved Black Formatting:** Retains formatting consistency with Black formatting.
- **External File Storage:** Store snapshots externally using `outsource(data)`.
- **Seamless Pytest Integration:** Integrated seamlessly with pytest for effortless testing.
- **Customizable:** code generation can be customized with [@customize_repr](https://15r10nk.github.io/inline-snapshot/latest/customize_repr)
- **Nested Snapshot Support:** snapshots can contain [other snapshots](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#inner-snapshots)
- **Fuzzy Matching:** Incorporate [dirty-equals](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#dirty-equals) for flexible comparisons within snapshots.
- **Dynamic Snapshot Content:** snashots can contain [non-constant values](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#is)
- **Comprehensive Documentation:** Access detailed [documentation](https://15r10nk.github.io/inline-snapshot/latest) for complete guidance.


## Usage

You can use `snapshot()` instead of the value which you want to compare with.

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


def test_something():
    assert 1548 * 18489 == snapshot()
```

You can now run the tests and record the correct values.

```
$ pytest --inline-snapshot=review
```

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


def test_something():
    assert 1548 * 18489 == snapshot(28620972)
```

The following examples show how you can use inline-snapshot in your tests. Take a look at the
[documentation](https://15r10nk.github.io/inline-snapshot/latest) if you want to know more.

<!-- inline-snapshot: create fix trim first_block outcome-passed=1 -->
``` python
from inline_snapshot import snapshot, outsource, external


def test_something():
    for number in range(5):
        # testing for numeric limits
        assert number <= snapshot(4)
        assert number >= snapshot(0)

    for c in "hello world":
        # test if something is part of a set
        assert c in snapshot(["h", "e", "l", "o", " ", "w", "r", "d"])

    s = snapshot(
        {
            0: {"square": 0, "pow_of_two": False},
            1: {"square": 1, "pow_of_two": True},
            2: {"square": 4, "pow_of_two": True},
            3: {"square": 9, "pow_of_two": False},
            4: {"square": 16, "pow_of_two": True},
        }
    )

    for number in range(5):
        # create sub-snapshots at runtime
        assert s[number]["square"] == number**2
        assert s[number]["pow_of_two"] == (
            (number & (number - 1) == 0) and number != 0
        )

    assert outsource("large string\n" * 1000) == snapshot(
        external("8bf10bdf2c30*.txt")
    )

    assert "generates\nmultiline\nstrings" == snapshot(
        """\
generates
multiline
strings\
"""
    )
```


`snapshot()` can also be used as parameter for functions:

<!-- inline-snapshot: create fix trim first_block outcome-passed=1 -->
``` python
from inline_snapshot import snapshot
import subprocess as sp
import sys


def run_python(cmd, stdout=None, stderr=None):
    result = sp.run([sys.executable, "-c", cmd], capture_output=True)
    if stdout is not None:
        assert result.stdout.decode() == stdout
    if stderr is not None:
        assert result.stderr.decode() == stderr


def test_cmd():
    run_python(
        "print('hello world')",
        stdout=snapshot(
            """\
hello world
"""
        ),
        stderr=snapshot(""),
    )

    run_python(
        "1/0",
        stdout=snapshot(""),
        stderr=snapshot(
            """\
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ZeroDivisionError: division by zero
"""
        ),
    )
```

<!-- -8<- [start:Feedback] -->
## Feedback

inline-snapshot provides some advanced ways to work with snapshots.

I would like to know how these features are used to further improve this small library.
Let me know if you've found interesting use cases for this library via [twitter](https://twitter.com/15r10nk), [fosstodon](https://fosstodon.org/deck/@15r10nk) or in the github [discussions](https://github.com/15r10nk/inline-snapshot/discussions/new?category=show-and-tell).

## Sponsors

I would like to thank my sponsors. Without them, I would not be able to invest so much time in my projects.

### Bronze sponsor 🥉

<p align="center">
  <a href="https://pydantic.dev/logfire">
    <img src="https://pydantic.dev/assets/for-external/pydantic_logfire_logo_endorsed_lithium_rgb.svg" alt="pydantic logfire" width="300"/>
  </a>
</p>

## Issues

If you encounter any problems, please [report an issue](https://github.com/15r10nk/inline-snapshot/issues) along with a detailed description.
<!-- -8<- [end:Feedback] -->

## License

Distributed under the terms of the [MIT](http://opensource.org/licenses/MIT) license, "inline-snapshot" is free and open source software.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "inline-snapshot",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Frank Hoffmann <15r10nk-git@polarbit.de>",
    "download_url": "https://files.pythonhosted.org/packages/43/31/9fb282bc713e56e677be1f5b4e55183874e56f8374be054f8a511f96736d/inline_snapshot-0.24.0.tar.gz",
    "platform": null,
    "description": "<!-- -8<- [start:Header] -->\n\n<p align=\"center\">\n  <a href=\"https://15r10nk.github.io/inline-snapshot/latest/\">\n    <img src=\"docs/assets/logo.svg\" width=\"500\" alt=\"inline-snapshot\">\n  </a>\n</p>\n\n![ci](https://github.com/15r10nk/inline-snapshot/actions/workflows/ci.yml/badge.svg?branch=main)\n[![Docs](https://img.shields.io/badge/docs-mkdocs-green)](https://15r10nk.github.io/inline-snapshot/latest/)\n[![pypi version](https://img.shields.io/pypi/v/inline-snapshot.svg)](https://pypi.org/project/inline-snapshot/)\n![Python Versions](https://img.shields.io/pypi/pyversions/inline-snapshot)\n[![PyPI - Downloads](https://img.shields.io/pypi/dw/inline-snapshot)](https://pypacktrends.com/?packages=inline-snapshot&time_range=2years)\n[![coverage](https://img.shields.io/badge/coverage-100%25-blue)](https://15r10nk.github.io/inline-snapshot/latest/contributing/#coverage)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/15r10nk)](https://github.com/sponsors/15r10nk)\n\n<!-- -8<- [end:Header] -->\n\n## Installation\n\nYou can install \"inline-snapshot\" via [pip](https://pypi.org/project/pip/):\n\n``` bash\npip install inline-snapshot\n```\n\n> [!IMPORTANT]\n> Hello, I would like to inform you about some changes. I have started to offer [insider](https://15r10nk.github.io/inline-snapshot/latest/insiders/) features for inline-snapshot. I will only release features as insider features if they will not cause problems for you when used in an open source project.\n> I hope sponsoring will allow me to spend more time working on open source projects.\n> Thank you for using inline-snapshot, the future will be \ud83d\ude80.\n\n## Key Features\n\n- **support for normal assertions:** inline-snapshot can now also fix normal assertions which do not use `snapshot()` like:\n\n    ``` python\n    assert 1 + 1 == 3\n    ```\n\n    You can learn [here](fix_assert.md) more about this feature.\n\n\n- **Intuitive Semantics:** `snapshot(x)` mirrors `x` for easy understanding.\n- **Versatile Comparison Support:** Equipped with\n    [`x == snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/),\n    [`x <= snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/cmp_snapshot/),\n    [`x in snapshot(...)`](https://15r10nk.github.io/inline-snapshot/latest/in_snapshot/), and\n    [`snapshot(...)[key]`](https://15r10nk.github.io/inline-snapshot/latest/getitem_snapshot/).\n- **Enhanced Control Flags:** Utilize various [flags](https://15r10nk.github.io/inline-snapshot/latest/pytest/) for precise control of which snapshots you want to change.\n- **Preserved Black Formatting:** Retains formatting consistency with Black formatting.\n- **External File Storage:** Store snapshots externally using `outsource(data)`.\n- **Seamless Pytest Integration:** Integrated seamlessly with pytest for effortless testing.\n- **Customizable:** code generation can be customized with [@customize_repr](https://15r10nk.github.io/inline-snapshot/latest/customize_repr)\n- **Nested Snapshot Support:** snapshots can contain [other snapshots](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#inner-snapshots)\n- **Fuzzy Matching:** Incorporate [dirty-equals](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#dirty-equals) for flexible comparisons within snapshots.\n- **Dynamic Snapshot Content:** snashots can contain [non-constant values](https://15r10nk.github.io/inline-snapshot/latest/eq_snapshot/#is)\n- **Comprehensive Documentation:** Access detailed [documentation](https://15r10nk.github.io/inline-snapshot/latest) for complete guidance.\n\n\n## Usage\n\nYou can use `snapshot()` instead of the value which you want to compare with.\n\n<!-- inline-snapshot: first_block outcome-passed=1 outcome-errors=1 -->\n``` python\nfrom inline_snapshot import snapshot\n\n\ndef test_something():\n    assert 1548 * 18489 == snapshot()\n```\n\nYou can now run the tests and record the correct values.\n\n```\n$ pytest --inline-snapshot=review\n```\n\n<!-- inline-snapshot: create outcome-passed=1 outcome-errors=1 -->\n``` python hl_lines=\"5\"\nfrom inline_snapshot import snapshot\n\n\ndef test_something():\n    assert 1548 * 18489 == snapshot(28620972)\n```\n\nThe following examples show how you can use inline-snapshot in your tests. Take a look at the\n[documentation](https://15r10nk.github.io/inline-snapshot/latest) if you want to know more.\n\n<!-- inline-snapshot: create fix trim first_block outcome-passed=1 -->\n``` python\nfrom inline_snapshot import snapshot, outsource, external\n\n\ndef test_something():\n    for number in range(5):\n        # testing for numeric limits\n        assert number <= snapshot(4)\n        assert number >= snapshot(0)\n\n    for c in \"hello world\":\n        # test if something is part of a set\n        assert c in snapshot([\"h\", \"e\", \"l\", \"o\", \" \", \"w\", \"r\", \"d\"])\n\n    s = snapshot(\n        {\n            0: {\"square\": 0, \"pow_of_two\": False},\n            1: {\"square\": 1, \"pow_of_two\": True},\n            2: {\"square\": 4, \"pow_of_two\": True},\n            3: {\"square\": 9, \"pow_of_two\": False},\n            4: {\"square\": 16, \"pow_of_two\": True},\n        }\n    )\n\n    for number in range(5):\n        # create sub-snapshots at runtime\n        assert s[number][\"square\"] == number**2\n        assert s[number][\"pow_of_two\"] == (\n            (number & (number - 1) == 0) and number != 0\n        )\n\n    assert outsource(\"large string\\n\" * 1000) == snapshot(\n        external(\"8bf10bdf2c30*.txt\")\n    )\n\n    assert \"generates\\nmultiline\\nstrings\" == snapshot(\n        \"\"\"\\\ngenerates\nmultiline\nstrings\\\n\"\"\"\n    )\n```\n\n\n`snapshot()` can also be used as parameter for functions:\n\n<!-- inline-snapshot: create fix trim first_block outcome-passed=1 -->\n``` python\nfrom inline_snapshot import snapshot\nimport subprocess as sp\nimport sys\n\n\ndef run_python(cmd, stdout=None, stderr=None):\n    result = sp.run([sys.executable, \"-c\", cmd], capture_output=True)\n    if stdout is not None:\n        assert result.stdout.decode() == stdout\n    if stderr is not None:\n        assert result.stderr.decode() == stderr\n\n\ndef test_cmd():\n    run_python(\n        \"print('hello world')\",\n        stdout=snapshot(\n            \"\"\"\\\nhello world\n\"\"\"\n        ),\n        stderr=snapshot(\"\"),\n    )\n\n    run_python(\n        \"1/0\",\n        stdout=snapshot(\"\"),\n        stderr=snapshot(\n            \"\"\"\\\nTraceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nZeroDivisionError: division by zero\n\"\"\"\n        ),\n    )\n```\n\n<!-- -8<- [start:Feedback] -->\n## Feedback\n\ninline-snapshot provides some advanced ways to work with snapshots.\n\nI would like to know how these features are used to further improve this small library.\nLet me know if you've found interesting use cases for this library via [twitter](https://twitter.com/15r10nk), [fosstodon](https://fosstodon.org/deck/@15r10nk) or in the github [discussions](https://github.com/15r10nk/inline-snapshot/discussions/new?category=show-and-tell).\n\n## Sponsors\n\nI would like to thank my sponsors. Without them, I would not be able to invest so much time in my projects.\n\n### Bronze sponsor \ud83e\udd49\n\n<p align=\"center\">\n  <a href=\"https://pydantic.dev/logfire\">\n    <img src=\"https://pydantic.dev/assets/for-external/pydantic_logfire_logo_endorsed_lithium_rgb.svg\" alt=\"pydantic logfire\" width=\"300\"/>\n  </a>\n</p>\n\n## Issues\n\nIf you encounter any problems, please [report an issue](https://github.com/15r10nk/inline-snapshot/issues) along with a detailed description.\n<!-- -8<- [end:Feedback] -->\n\n## License\n\nDistributed under the terms of the [MIT](http://opensource.org/licenses/MIT) license, \"inline-snapshot\" is free and open source software.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "golden master/snapshot/approval testing library which puts the values right into your source code",
    "version": "0.24.0",
    "project_urls": {
        "Changelog": "https://15r10nk.github.io/inline-snapshot/latest/changelog/",
        "Discussions": "https://github.com/15r10nk/inline-snapshots/discussions",
        "Documentation": "https://15r10nk.github.io/inline-snapshot/latest",
        "Funding": "https://github.com/sponsors/15r10nk",
        "Homepage": "https://15r10nk.github.io/inline-snapshot/latest",
        "Issues": "https://github.com/15r10nk/inline-snapshots/issues",
        "Repository": "https://github.com/15r10nk/inline-snapshot/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "82438bc5960a35b14cff168be441a3f18eb7b3dd2b734ed5d5a4050bf6f44958",
                "md5": "2fa0d36ce6a78527d4bfd7a5c82a9419",
                "sha256": "43a19e76799f86a97b28492883d99b02c96377e0aac2e56aa19b1257c64f3759"
            },
            "downloads": -1,
            "filename": "inline_snapshot-0.24.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2fa0d36ce6a78527d4bfd7a5c82a9419",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 50970,
            "upload_time": "2025-07-15T03:41:27",
            "upload_time_iso_8601": "2025-07-15T03:41:27.772696Z",
            "url": "https://files.pythonhosted.org/packages/82/43/8bc5960a35b14cff168be441a3f18eb7b3dd2b734ed5d5a4050bf6f44958/inline_snapshot-0.24.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "43319fb282bc713e56e677be1f5b4e55183874e56f8374be054f8a511f96736d",
                "md5": "2597693b0ecad27988aa1488158e13a9",
                "sha256": "6aa304f2904103a449f3213e059728da5f1c34757f943efca837b4669f290843"
            },
            "downloads": -1,
            "filename": "inline_snapshot-0.24.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2597693b0ecad27988aa1488158e13a9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 263374,
            "upload_time": "2025-07-15T03:41:29",
            "upload_time_iso_8601": "2025-07-15T03:41:29.370889Z",
            "url": "https://files.pythonhosted.org/packages/43/31/9fb282bc713e56e677be1f5b4e55183874e56f8374be054f8a511f96736d/inline_snapshot-0.24.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-15 03:41:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "15r10nk",
    "github_project": "inline-snapshots",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "inline-snapshot"
}
        
Elapsed time: 0.57927s