inline-snapshot 0.30.1


pip install inline-snapshot

  Latest version

Released: Oct 20, 2025


Meta
Author: Frank Hoffmann
Requires Python: >=3.8

Classifiers

Development Status
  • 4 - Beta

Framework
  • Pytest

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • Software Development :: Testing

inline-snapshot

ci Docs pypi version Python Versions PyPI - Downloads coverage GitHub Sponsors

Installation

You can install "inline-snapshot" via pip:

pip install inline-snapshot

Key Features

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

    assert 1 + 1 == 3
    

    You can learn here more about this feature.

  • Intuitive Semantics: snapshot(x) mirrors x for easy understanding.

  • Versatile Comparison Support: Equipped with x == snapshot(...), x <= snapshot(...), x in snapshot(...), and snapshot(...)[key].

  • Enhanced Control Flags: Utilize various flags 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

  • Nested Snapshot Support: snapshots can contain other snapshots

  • Fuzzy Matching: Incorporate dirty-equals for flexible comparisons within snapshots.

  • Dynamic Snapshot Content: snapshots can contain non-constant values

  • Comprehensive Documentation: Access detailed documentation for complete guidance.

Usage

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

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
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 if you want to know more.

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("hash:8bf10bdf2c30*.txt")
    )

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

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

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
"""
        ),
    )

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, fosstodon or in the github discussions.

Sponsors

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

Silver sponsor ๐Ÿฅˆ

logfire

I have also started to offer insider 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 ๐Ÿš€.

Issues

If you encounter any problems, please report an issue along with a detailed description.

License

Distributed under the terms of the MIT license, "inline-snapshot" is free and open source software.

0.30.1 Oct 20, 2025
0.30.0 Oct 15, 2025
0.29.4 Oct 13, 2025
0.29.3 Oct 04, 2025
0.29.2 Oct 01, 2025
0.29.1 Sep 24, 2025
0.29.0 Sep 15, 2025
0.28.0 Aug 24, 2025
0.27.2 Aug 11, 2025
0.27.1 Aug 08, 2025
0.27.0 Aug 05, 2025
0.26.0 Jul 31, 2025
0.25.3 Jul 27, 2025
0.25.2 Jul 25, 2025
0.25.1 Jul 24, 2025
0.25.0 Jul 23, 2025
0.24.0 Jul 15, 2025
0.23.2 May 28, 2025
0.23.1 May 26, 2025
0.23.0 Apr 25, 2025
0.22.3 Apr 14, 2025
0.22.2 Apr 14, 2025
0.22.1 Apr 11, 2025
0.22.0 Apr 03, 2025
0.21.3 Apr 02, 2025
0.21.2 Mar 31, 2025
0.21.1 Mar 29, 2025
0.21.0 Mar 28, 2025
0.20.10 Mar 26, 2025
0.20.9 Mar 23, 2025
0.20.8 Mar 20, 2025
0.20.7 Mar 14, 2025
0.20.6 Mar 13, 2025
0.20.5 Mar 04, 2025
0.20.4 Mar 03, 2025
0.20.3 Feb 28, 2025
0.20.2 Feb 13, 2025
0.20.1 Feb 04, 2025
0.20.0 Feb 01, 2025
0.19.3 Jan 15, 2025
0.19.2 Jan 15, 2025
0.19.1 Jan 12, 2025
0.19.0 Jan 10, 2025
0.18.2 Jan 02, 2025
0.18.1 Dec 22, 2024
0.18.0 Dec 21, 2024
0.17.1 Dec 17, 2024
0.17.0 Dec 14, 2024
0.16.0 Dec 12, 2024
0.15.1 Dec 10, 2024
0.15.0 Dec 10, 2024
0.14.2 Dec 07, 2024
0.14.1 Dec 04, 2024
0.14.0 Nov 10, 2024
0.13.4 Nov 07, 2024
0.13.3 Sep 24, 2024
0.13.2 Sep 24, 2024
0.13.1 Sep 18, 2024
0.13.0 Sep 10, 2024
0.12.1 Aug 05, 2024
0.12.0 Jul 22, 2024
0.11.0 Jul 07, 2024
0.10.2 May 28, 2024
0.10.1 May 26, 2024
0.10.0 May 21, 2024
0.9.0 May 07, 2024
0.8.2 Apr 24, 2024
0.8.1 Apr 22, 2024
0.8.0 Apr 09, 2024
0.7.0 Feb 27, 2024
0.6.1 Jan 28, 2024
0.6.0 Dec 10, 2023
0.5.2 Nov 13, 2023
0.5.1 Oct 20, 2023
0.5.0 Oct 15, 2023
0.4.0 Sep 29, 2023
0.3.2 Jul 31, 2023
0.3.1 Jul 14, 2023
0.3.0 Jul 12, 2023
0.2.1 Jul 09, 2023
0.2.0 Jun 20, 2023
0.1.2 Dec 11, 2022
0.1.1 Dec 08, 2022
0.1.0 Jul 25, 2022

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
asttokens (>=2.0.5)
executing (>=2.2.0)
pytest (>=8.3.4)
rich (>=13.7.1)
tomli (>=2.0.0)