Registry / testing / snapshottest

snapshottest

JSON →
library0.6.0pypypi✓ verified 28d ago

`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.

pip install snapshottest
INSTALL
IMPORT
SIG · SNAPSHOTTEST
S
snapshottest
testingpythonv0.6.0
Install
2.0s avg
Import
198ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.096s · 18.3MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.0s · import 0.142s · 28MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

snapshot
✓ from snapshottest import snapshot
✗ from snapshottest import snapshot

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.
Debug
Known issues
gotchaSnapshot tests can be flaky or misleading if they include dynamic content such as dates, timestamps, unique IDs, or random numbers. These values change on every run, causing unnecessary test failures.
fix
Mock or normalize dynamic values before taking a snapshot. For example, replace `datetime.now()` with a fixed, known date during testing.
affects: All
gotchaLarge or overly broad snapshots are difficult to review and maintain. Developers often become 'snapshot fatigued' and blindly update snapshots without scrutinizing the changes, which defeats the purpose of testing.
fix
Keep snapshots small and focused. Test specific, isolated parts of your output rather than entire component trees or API responses. Break down complex outputs into multiple, granular snapshots if necessary.
affects: All
gotcha`snapshottest` can be tightly coupled to implementation details. Minor refactoring or internal changes (e.g., changing HTML attributes or JSON keys that don't affect behavior) can cause widespread snapshot failures.
fix
Use snapshot testing primarily for stable output contracts (like API responses or data transformations) rather than frequently changing UI structures. Supplement with more explicit unit or integration tests for core logic.
affects: All
gotchaWhen using `unittest.TestCase` subclasses in a pytest environment, the `snapshot` fixture is not directly available. Attempting to use `snapshot` as a parameter in a `TestCase` method will fail.
fix
To use the pytest `snapshot` fixture within `unittest.TestCase` or `snapshottest.TestCase` methods, a custom pytest fixture must be created in `conftest.py` to wrap and expose the `snapshot` fixture to the class instance. This is shown in issue #53 on the GitHub repository.
affects: All
gotchaThe `snapshottest` library has not seen updates since September 2020. More actively maintained alternatives like `syrupy` or `pytest-snapshot` offer additional features such as custom serialization, better snapshot file organization, and support for newer Python versions and frameworks.
fix
Consider evaluating alternative snapshot testing libraries for Python, especially for new projects or if advanced features like custom serializers are required.
affects: 0.6.0 and earlier
Upgrade
Version history
0.6.0latest on PyPI · released Sep 29, 2020
Audit
Dependencies
pytestoptionalRequired for pytest integration, a common use case.
Agent activity
32 hits · last 30 days
node
28
Resources
snapshottest — pip install snapshottest · libregistry