snapshottest

0.6.0 · maintenance · verified Sat Apr 11

`snapshottest` is a Python library that provides utilities for snapshot testing across various testing frameworks, including pytest, unittest, Django, and Nose. It captures the serialized output of APIs or data structures and compares them against a stored reference, helping developers identify unintended changes and regressions. The library is currently at version 0.6.0, with its last release in September 2020, suggesting a maintenance-focused cadence rather than active feature development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates using `snapshottest` with pytest. The first time the test runs, it generates a snapshot file containing the serialized `my_complex_data`. Subsequent runs compare the current output against this snapshot. If an intentional change occurs, use `pytest --snapshot-update` to re-record the snapshot.

import pytest

def test_my_data_structure(snapshot):
    # Simulate some data or API response
    my_complex_data = {
        "id": 123,
        "name": "Test User",
        "settings": {"theme": "dark", "notifications": True},
        "items": ["apple", "banana", "cherry"]
    }
    snapshot.assert_match(my_complex_data)

# To run this test:
# 1. Save it as e.g., `test_my_app.py`
# 2. Run `pytest` from your terminal. The first run will create a snapshot file.
# 3. If the output changes and it's intentional, run `pytest --snapshot-update` to update the snapshot.

view raw JSON →