Registry / testing / inline-snapshot

inline-snapshot

JSON →
library0.35.4pypypi✓ verified 22d ago

inline-snapshot is a Python library for golden master/snapshot/approval testing, designed to store expected values directly within your source code. It automates the process of recording, storing, and updating these values, integrating seamlessly with pytest for an enhanced developer experience. The library is currently at version 0.32.6 and receives regular updates, often with minor patch releases to address bugs and improve compatibility.

pip install inline-snapshot
INSTALL
IMPORT
SIG · INLINE-SNAPSHOT
I
inline-snapshot
testingpythonv0.35.4
Install
3.4s avg
Import
766ms
Disk
35MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.35.4 · 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.103.95 runs
installs and imports cleanly · install 0.0s · import 0.794s · 36.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.4s · import 0.738s · 37MB
35MB installed
● package 35MB
Code
Verified usage

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

snapshot
from inline_snapshot import snapshot
external
from inline_snapshot import external
Used for storing snapshots in external files.
outsource
from inline_snapshot import outsource
Used for storing snapshots externally.

This quickstart demonstrates the core functionality of inline-snapshot. Initially, `snapshot()` is called without an argument. Running `pytest --inline-snapshot=create` will execute the test, capture the actual result, and automatically insert it as an argument to `snapshot()` in your source code. Subsequent runs will compare against this recorded value.

from inline_snapshot import snapshot import pytest def test_calculation(): result = 1548 * 18489 assert result == snapshot() # To run this test and generate the snapshot value: # pytest --inline-snapshot=create your_test_file.py # The 'snapshot()' in the code will be updated to 'snapshot(28620972)'.
Debug
Known issues
breakingAs of v0.31.0, using `external()` for external snapshots is restricted to files within your configured test directories (default `tests/`). Using it outside will raise an exception.
fix
Ensure `external()` calls are made only from files within the `tests/` directory or a custom directory configured via `tool.inline-snapshot.test-dir` in `pyproject.toml`.
affects: >=0.31.0
breakingSupport for Python 3.8 has been removed in v0.32.0.
fix
Upgrade your Python environment to 3.9 or newer.
affects: >=0.32.0
gotchaA single `snapshot()` instance can only be used with one assertion operation (e.g., `==`, `<=`, `in`). Reusing the same `snapshot` object for multiple comparisons in a single test will not work as expected.
fix
Create a new `snapshot()` call for each distinct comparison or operation within your test (e.g., `assert value1 == snapshot()`, `assert value2 <= snapshot()`).
affects: All versions
gotchaCopying tests with external snapshots (using `external()`) might lead to duplicate UUIDs, which can cause issues.
fix
After copying a test with `external()`, reset the snapshot to an empty `external()` and regenerate it using `pytest --inline-snapshot=create` or `review`.
affects: All versions
gotchaPydantic models, attrs, and dataclasses with `NewType`-typed fields generated incorrect snapshots, failing to wrap the field value with the `NewType` constructor.
fix
Upgrade to `inline-snapshot` v0.32.6 or newer (requires Python >= 3.10 for the fix to apply). If on an older Python version, consider normalizing data to built-in types before snapshotting.
affects: <0.32.6
gotchaRunning tests with `-k` (keyword filtering) could previously raise `UsageError("unmanaged values can not be compared with snapshots")` during session teardown.
fix
Upgrade to `inline-snapshot` v0.32.4 or newer to resolve this issue.
affects: <0.32.4
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'inline_snapshot'
The 'inline-snapshot' package has not been installed or is misspelled during import.
fix
Install the package using pip: `pip install inline-snapshot` or ensure the import statement is `from inline_snapshot import snapshot`.
TypeError: This snapshot cannot be use with '==', because it was previously used with 'x <= snapshot'.
This error occurs when you attempt to use the equality operator (`==`) with a snapshot that was previously recorded or intended for a different comparison type, such as less than or equal to (`<=`).
fix
Ensure that if a snapshot was created using `value <= snapshot()`, it is consistently used with `<=` and not `==`. If you need both, consider using separate snapshots or updating the snapshot appropriately with `pytest --inline-snapshot=fix`.
AttributeError: 'EqValue' object has no attribute '_changes'
This error has been observed in specific scenarios, particularly when 'inline-snapshot' is used in conjunction with other pytest plugins like `pytest-run-parallel`, indicating a potential compatibility issue or an internal state management conflict.
fix
Check for known compatibility issues with other pytest plugins on the `inline-snapshot` GitHub issues page. Temporarily disable conflicting plugins or upgrade both `inline-snapshot` and other plugins to their latest versions. As a workaround, disabling `inline-snapshot` for parallel test runs might be necessary if the issue persists.
AssertionError
This is the general error encountered when a test using `snapshot()` is run for the first time, or when the actual value no longer matches the previously recorded snapshot, as the `snapshot()` function is initially empty or contains an outdated value.
fix
To create or update the snapshot, run your pytest command with the `--inline-snapshot=create` or `--inline-snapshot=fix` flag, e.g., `pytest your_test_file.py --inline-snapshot=create`.
Upgrade
Version history
0.35.4latest on PyPI · released Aug 11, 2026
Audit
Dependencies
pytestrequiredSeamless integration and primary use case for running tests.
dirty-equalsoptionalUsed for fuzzy matching and flexible comparisons within snapshots.
pydanticoptionalSupports snapshotting of Pydantic models.
attrsoptionalSupports snapshotting of attrs classes.
dataclassesoptionalSupports snapshotting of dataclasses.
Agent activity
5 hits · last 30 days
node
4
Resources
inline-snapshot — pip install inline-snapshot · libregistry