pytest-insta

raw JSON →
0.4.1 verified Mon Apr 27 auth: no python

A practical snapshot testing plugin for pytest, providing a simple way to compare test results against stored snapshots. Current version is 0.4.1, with a release cadence of approximately monthly.

pip install pytest-insta
error AttributeError: module 'pytest_insta' has no attribute 'snapshot'
cause Trying to import snapshot as a function instead of using the fixture.
fix
Do not import; use the fixture in test function argument: def test_foo(snapshot):
error pytest: error: unrecognized arguments: --insta
cause pytest-insta not installed or not enabled.
fix
Install with pip install pytest-insta and ensure no conftest disables the plugin.
breaking Version 0.4.0 changed the default snapshot storage format from .snap to .json. Existing .snap files will not be recognized unless migrated.
fix Re-run tests with --insta-update to regenerate snapshots in new format.
deprecated The 'snapshot' fixture argument 'name' is deprecated in 0.4.0; use 'snapshot_name' fixture instead.
fix Use the built-in fixture 'snapshot_name' to specify custom snapshot names.
gotcha Snapshot tests are not deterministic for unordered data (e.g., dicts with floating point). Snapshots are compared as JSON strings.
fix Sort data or use custom serializers. Consider using pytest.approx for floats.

Basic snapshot test using the snapshot fixture. Run with 'pytest --insta' to record snapshots.

# content of test_example.py
import pytest
import requests

def test_with_snapshot(snapshot):
    response = requests.get('https://api.github.com')
    assert snapshot() == response.json()