{"id":4054,"library":"inline-snapshot","title":"inline-snapshot","description":"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.","status":"active","version":"0.32.6","language":"en","source_language":"en","source_url":"https://github.com/15r10nk/inline-snapshot/","tags":["testing","snapshot testing","pytest","golden master","developer tools","approval testing"],"install":[{"cmd":"pip install inline-snapshot","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Seamless integration and primary use case for running tests.","package":"pytest","optional":false},{"reason":"Used for fuzzy matching and flexible comparisons within snapshots.","package":"dirty-equals","optional":true},{"reason":"Supports snapshotting of Pydantic models.","package":"pydantic","optional":true},{"reason":"Supports snapshotting of attrs classes.","package":"attrs","optional":true},{"reason":"Supports snapshotting of dataclasses.","package":"dataclasses","optional":true}],"imports":[{"symbol":"snapshot","correct":"from inline_snapshot import snapshot"},{"note":"Used for storing snapshots in external files.","symbol":"external","correct":"from inline_snapshot import external"},{"note":"Used for storing snapshots externally.","symbol":"outsource","correct":"from inline_snapshot import outsource"}],"quickstart":{"code":"from inline_snapshot import snapshot\nimport pytest\n\ndef test_calculation():\n    result = 1548 * 18489\n    assert result == snapshot()\n\n# To run this test and generate the snapshot value:\n# pytest --inline-snapshot=create your_test_file.py\n# The 'snapshot()' in the code will be updated to 'snapshot(28620972)'.","lang":"python","description":"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."},"warnings":[{"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`.","message":"As 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.","severity":"breaking","affected_versions":">=0.31.0"},{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Support for Python 3.8 has been removed in v0.32.0.","severity":"breaking","affected_versions":">=0.32.0"},{"fix":"Create a new `snapshot()` call for each distinct comparison or operation within your test (e.g., `assert value1 == snapshot()`, `assert value2 <= snapshot()`).","message":"A 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"After copying a test with `external()`, reset the snapshot to an empty `external()` and regenerate it using `pytest --inline-snapshot=create` or `review`.","message":"Copying tests with external snapshots (using `external()`) might lead to duplicate UUIDs, which can cause issues.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Pydantic models, attrs, and dataclasses with `NewType`-typed fields generated incorrect snapshots, failing to wrap the field value with the `NewType` constructor.","severity":"gotcha","affected_versions":"<0.32.6"},{"fix":"Upgrade to `inline-snapshot` v0.32.4 or newer to resolve this issue.","message":"Running tests with `-k` (keyword filtering) could previously raise `UsageError(\"unmanaged values can not be compared with snapshots\")` during session teardown.","severity":"gotcha","affected_versions":"<0.32.4"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}