Snapshot testing library.
Project description
SnappierShot
Add snapshot testing to your testing toolkit.
Installation
$ pip install snappiershot
Configuration
SnappierShot is following the trend of packages in performing project-wide configuration through the pyproject.toml file established by PEP 518.
Within the pyproject.toml file, all SnappierShot configuration can be found under the
[tool.snappiershot] heading.
Example (with default values):
[tool.snappiershot]
file_format = "json"
float_absolute_tolerance = 1e-6
float_relative_tolerance = 0.001
full_diff = false
json_indentation = 4
Usage
SnappierShot allows you to take a "snapshot" of data the first time that a test
is run, and stores it nearby in a .snapshots directory. Then, for all
subsequent times that test is run, the data is assert to "match" the original
data.
Pytest Example
def test_something(snapshot):
""" Test that something works as expected"""
# Arrange
x = 1
y = 2
# Act
result = x + y
# Assert
snapshot.assert_match(result)
No Test Runner Example
from snappiershot import Snapshot
def test_something():
""" Test that something works as expected"""
# Arrange
x = 1
y = 2
# Act
result = x + y
# Assert
with Snapshot() as snapshot
snapshot.assert_match(result)
test_something()
Raises
Snappiershot also allows you to take a "snapshot" errors that are raised during the execution of a code block. This allows you to track how and when errors are reported more easily.
def fallible_function():
""" A function with an error state. """
raise RuntimeError("An error occurred!")
def test_fallible_function(snapshot):
""" Test that errors are being reported as expected"""
# Arrange
# Act & Assert
with snapshot.raises(RuntimeError):
fallible_function()
Support Types:
- Primitives (
bool,int,float,None,str) - Numerics (
complex) - Collections (
lists,tuples,sets) - Dictionaries
- Classes (with an underlying
__dict__) - Classes with custom encoding (by defining a
__snapshot__method).
Contributing
See CONTRIBUTING.md
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snappiershot-1.0.0.tar.gz.
File metadata
- Download URL: snappiershot-1.0.0.tar.gz
- Upload date:
- Size: 30.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/2.7.17 Linux/5.4.0-1036-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75c20b8fca96de5b219015a930efbdf715a8a747db275baea1dd1e1e1cd28897
|
|
| MD5 |
04eab6f73b28329e5fb11d6dffab670f
|
|
| BLAKE2b-256 |
242091e3cf2199aa3134dac59e903bd5564c269a941370d7f7afdc387ea41c0b
|
File details
Details for the file snappiershot-1.0.0-py3-none-any.whl.
File metadata
- Download URL: snappiershot-1.0.0-py3-none-any.whl
- Upload date:
- Size: 35.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/2.7.17 Linux/5.4.0-1036-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5944753807e737eff80fa863eb8a3e46e79492c14670207a23074163d8d10a1
|
|
| MD5 |
c48767fe3d58f2eda5d4cc170a44f937
|
|
| BLAKE2b-256 |
fdc265ba9191386a4d6a843630074cf2697995e466a543155f085aa3dbc52d18
|