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-snapshotVerified import paths — ran on the pinned version, not inferred.
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.
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`.
Upgrade your Python environment to 3.9 or newer.
Create a new `snapshot()` call for each distinct comparison or operation within your test (e.g., `assert value1 == snapshot()`, `assert value2 <= snapshot()`).
After copying a test with `external()`, reset the snapshot to an empty `external()` and regenerate it using `pytest --inline-snapshot=create` or `review`.
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.
Upgrade to `inline-snapshot` v0.32.4 or newer to resolve this issue.
Install the package using pip: `pip install inline-snapshot` or ensure the import statement is `from inline_snapshot import snapshot`.
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`.
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.
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`.