Skip to main content

Varsnap

Project description

Varsnap Python

Build Status

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 twine
python setup.py sdist bdist_wheel
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.

Files for varsnap, version 1.5.0
Filename, size File type Python version Upload date Hashes
Filename, size varsnap-1.5.0.tar.gz (10.4 kB) File type Source Python version None Upload date Hashes View
Filename, size varsnap-1.5.0-py3-none-any.whl (14.3 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page