Skip to main content

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

Project description

inline-snapshot

Docs pypi version PyPI - Downloads coverage GitHub Sponsors

create and update inline snapshots in your code.

Installation

You can install "inline-snapshot" via pip:

pip install inline-snapshot

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


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)

More information can be found in the documentation.

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.3.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

inline_snapshot-0.3.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: inline_snapshot-0.3.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.0 Linux/5.10.0-23-amd64

File hashes

Hashes for inline_snapshot-0.3.1.tar.gz
Algorithm Hash digest
SHA256 dffb88591be2d8c0809e458a10de13a101b93cc7014ca39b94101472674e3c47
MD5 1eb1b957965d58bb62cbe3d2f9aa2eae
BLAKE2b-256 e90e8d79231cae774567c0834afc01fc69b9451e898e108161c687416c077931

See more details on using hashes here.

File details

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

File metadata

  • Download URL: inline_snapshot-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.0 Linux/5.10.0-23-amd64

File hashes

Hashes for inline_snapshot-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec72f74ee7072c2a17f6e8c8988d2526c5781804bf2e7ca3c644596fcb6026c0
MD5 c78fddd46b9fc187cf3fe697aeb94e73
BLAKE2b-256 679a1a6d34b36beb715448709f1016d4357f32e696e097e53acbca9fbae62953

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