golden master/snapshot/approval testing library which puts the values right into your source code
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file inline_snapshot-0.5.1.tar.gz
.
File metadata
- Download URL: inline_snapshot-0.5.1.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.0 Linux/6.1.0-13-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb20ba775af1a5397a179774f51e50c0ac8d83065cc98afbedec161db13ef7ba |
|
MD5 | 2745158f685b615bc5e2f848b932027e |
|
BLAKE2b-256 | 914f8bf3811227f54175ab7a395eb22440ea16f63164e590ef0e4eccb7a397a7 |
File details
Details for the file inline_snapshot-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: inline_snapshot-0.5.1-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.0 Linux/6.1.0-13-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 215823c7bb733548fbd383c7ae2d8653ca51067380dd2b6d7d50ed81b511e85c |
|
MD5 | b8e5e0558096eb4bbbe0451f4d6816e0 |
|
BLAKE2b-256 | d2fe175ed060d05b9f920ba912e59e4f09b035191ab4146250beddbbf7505539 |