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
Hashes for snappiershot-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 683bd48a8239a865768250508a0227bbef44932405491b905edf91797c61328b |
|
MD5 | 28d929c9eaaa8646949d33fa92c9d4d4 |
|
BLAKE2b-256 | c5506f5d690aca1e554a3c186ae2ae1c726adc937f3cf16dd60cf63aedd17d32 |