Detect if running in a testing environment and control if methods act (either no-op in a test, or only act in a test)
Project description
VW
This module provides decorators that turn on or off the decorated method depending on whether it is running in a testing environment or not.
NOTE: The name vw was chosen for convenience and is not intended as commentary on any political topic real or imagined.
Why?
Have you ever found yourself wanting an easy way to turn off the logging when running in tests?
What about database access?
Mocking works well for your own code, but what about when a user imports your library?
This is what this tool is meant to solve.
Controlling
By using python-decouple, the following variables can be set in a settings.ini file, or a .env file, or as variables in the environment.
VW_IGNORE-> causes VW to ignore if it is in a test environment (no_opstill acts, andtests_onlywill not)VW_ALWAYS-> (NOTE:VW_IGNOREtakes precedence over this var) causes VW to behave like it is always in a test environment (no_opis always a no-op)
Examples
-
Using an in-memory db for tests:
import sqlite3 import vw _con = sqlite3.connect(":memory:" if vw.is_test_env() else "database.sqlite3")
-
Logging to a local file for tests
import logging import vw _root_logger = logging.getLogger(None) _root_logger.addHandler(logging.FileHandler("test.log" if vw.is_test_env() else "//path/to/server/log.txt"))
-
Avoid doing things in unit/component/integration tests that should only be done in production
import requests import vw @vw.no_op def send_tornado_warning(): requests.post(...)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file import_volkswagen-0.1.2.tar.gz.
File metadata
- Download URL: import_volkswagen-0.1.2.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
786fc3936c65112f9ee9cb6eee9e08596191f986bc8b1f23f3ec42f1a5399238
|
|
| MD5 |
b5eacbcd0dbb28c5af6212d3ace56b0b
|
|
| BLAKE2b-256 |
4dfad0d05648705a41c6620c0d7b110a9291627b30a2709907251399703ef97a
|
Provenance
The following attestation bundles were made for import_volkswagen-0.1.2.tar.gz:
Publisher:
Release.yml on mshafer1/py-vw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
import_volkswagen-0.1.2.tar.gz -
Subject digest:
786fc3936c65112f9ee9cb6eee9e08596191f986bc8b1f23f3ec42f1a5399238 - Sigstore transparency entry: 183149217
- Sigstore integration time:
-
Permalink:
mshafer1/py-vw@01fb6ad3030572b92bb49b76dd46dce41a63145e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mshafer1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
Release.yml@01fb6ad3030572b92bb49b76dd46dce41a63145e -
Trigger Event:
release
-
Statement type:
File details
Details for the file import_volkswagen-0.1.2-py3-none-any.whl.
File metadata
- Download URL: import_volkswagen-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f661d294fc85f833bbcc824b2d03b1157bc149cc20fddcac234cce59c3d7b94c
|
|
| MD5 |
142062dbd0279b037d42dbb2e04d0b99
|
|
| BLAKE2b-256 |
127eff072f94573e5f6e7d416406b38cde1a4b0968882a916a715953e492057a
|
Provenance
The following attestation bundles were made for import_volkswagen-0.1.2-py3-none-any.whl:
Publisher:
Release.yml on mshafer1/py-vw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
import_volkswagen-0.1.2-py3-none-any.whl -
Subject digest:
f661d294fc85f833bbcc824b2d03b1157bc149cc20fddcac234cce59c3d7b94c - Sigstore transparency entry: 183149219
- Sigstore integration time:
-
Permalink:
mshafer1/py-vw@01fb6ad3030572b92bb49b76dd46dce41a63145e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mshafer1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
Release.yml@01fb6ad3030572b92bb49b76dd46dce41a63145e -
Trigger Event:
release
-
Statement type: