Skip to main content

Python client for Varsnap, a snapshot testing service that records and compares function inputs and outputs

Project description

Varsnap Python

Build Status Maintainability Code Coverage

Python Varsnap Client

Installation

Install from PyPI - pip install varsnap

Requirements

The client depends on three environment variables to be set:

  • VARSNAP - Should be either true or false. Varsnap will be disabled if the variable is anything other than true.
  • ENV - If set to development, the client will receive events from production. If set to production, the client will emit events.
  • VARSNAP_PRODUCER_TOKEN - Only clients with this token may emit production snapshots. Copied from https://www.varsnap.com/user/
  • VARSNAP_CONSUMER_TOKEN - Only clients with this token may emit development snapshots. Copied from https://www.varsnap.com/user/

Usage

Add the varsnap decorator in front of any function you'd like to make better:

from varsnap import varsnap


@varsnap
def example(args, **kwargs):
    return 'output'

Testing

With the proper environment variables set, in a test file, add:

import unittest
from varsnap import test

class TestIntegration(unittest.TestCase):
    def test_varsnap(self):
        matches, logs = test()
        if matches is None:
            raise unittest.case.SkipTest('No Snaps found')
        self.assertTrue(matches, logs)

If you're testing a Flask application, set up a test request context when testing:

# app = Flask()
with app.test_request_context():
    matches, logs = test()

Troubleshooting

Decorators changing function names

Using decorators may change the name of functions. In order to not confuse varsnap, set the decorated function's __qualname__ and __signature__ to match the original function:

import inspect


def decorator(func):
    def decorated(*args, **kwargs):
        func(*args, **kwargs)
    decorated.__qualname__ = func.__qualname__
    wrapper.__signature__ = inspect.signature(func)
    return decorated

Publishing

pip install build twine
python -m build
twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

varsnap-1.5.10.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

varsnap-1.5.10-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file varsnap-1.5.10.tar.gz.

File metadata

  • Download URL: varsnap-1.5.10.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for varsnap-1.5.10.tar.gz
Algorithm Hash digest
SHA256 d58a6e53440adbf3274e802f9319cdc28a2a5be8fa3f3896c2177a0d5e48a726
MD5 eceb85abb051937e1c3fd41ea2faa6c0
BLAKE2b-256 14f72da9974b3b471844996860f373ba8182b457bb73b4fd732d0b016da8be39

See more details on using hashes here.

Provenance

The following attestation bundles were made for varsnap-1.5.10.tar.gz:

Publisher: publish.yml on albertyw/varsnap-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file varsnap-1.5.10-py3-none-any.whl.

File metadata

  • Download URL: varsnap-1.5.10-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for varsnap-1.5.10-py3-none-any.whl
Algorithm Hash digest
SHA256 fdca541a44ae4d04518ce1933006ae9c4b2946121f27064dd9c80976dcdddf71
MD5 7d57600f9c0bc61889ec5f371dc5fce4
BLAKE2b-256 07baadf74263b87a54c5554443f82e30d772339ad71638f57d4905a807efa994

See more details on using hashes here.

Provenance

The following attestation bundles were made for varsnap-1.5.10-py3-none-any.whl:

Publisher: publish.yml on albertyw/varsnap-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page