Skip to main content

golden master/snapshot/approval testing library which puts the values right into your source code

Project description

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

  • 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.
  • 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=create
from inline_snapshot import snapshot


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

inline-snapshot provides more advanced features like:

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

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inline_snapshot-0.8.0.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

inline_snapshot-0.8.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file inline_snapshot-0.8.0.tar.gz.

File metadata

  • Download URL: inline_snapshot-0.8.0.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.1.0-18-amd64

File hashes

Hashes for inline_snapshot-0.8.0.tar.gz
Algorithm Hash digest
SHA256 92338c400ea8fe3e34fc287d67ce46bbf1bae172c9a32fc0d120091201371317
MD5 6358363fa381b186d5dd07fdd5336024
BLAKE2b-256 b05f663a53c6e2b55f695d5c534290474a4e2ead374b456c20487c0e080646cb

See more details on using hashes here.

File details

Details for the file inline_snapshot-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: inline_snapshot-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.1.0-18-amd64

File hashes

Hashes for inline_snapshot-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e15ed3d71c721375174607fb5765ec6be85fb99c5447d142f62b62db8fc3e96
MD5 8c2c3018cf012a99c2ef5d8919731c54
BLAKE2b-256 3d2c8b91a35e4d318e89eeb44749fd2f7e24e0b77ee370bd8d7c3dfa1f3c8ab1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page