Varsnap
Project description
Varsnap Python
Installation
Install from PyPI - pip install varsnap
Requirements
The client depends on three environment variables to be set:
VARSNAP
- Should be eithertrue
orfalse
. Varsnap will be disabled if the variable is anything other thantrue
.ENV
- If set todevelopment
, the client will receive events from production. If set toproduction
, 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file varsnap-1.5.8.tar.gz
.
File metadata
- Download URL: varsnap-1.5.8.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfa674ceac52e53efe6639c394a050aaddfba10985ae3bf95e0bd9bfc7f55a1a |
|
MD5 | 27b3e45075095a1bbb174eb1f1251542 |
|
BLAKE2b-256 | 444652f0908e8584d493986d5fb2df8cb649598701b60918f73fb5b9d81902f5 |
File details
Details for the file varsnap-1.5.8-py3-none-any.whl
.
File metadata
- Download URL: varsnap-1.5.8-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6f6adf05174b32ae1509666c0b3fad5d4954048f84ad18fd4daa331af6a4a0e |
|
MD5 | ed2c941159b20ffe5a6e52908c35c1c8 |
|
BLAKE2b-256 | 21084259a284fc4ebb828656879147f302716a7393e5ebd12d240d1d72b882b0 |