Simple tools for temporatily injecting variables into the environment
Project description
Inject Environment Variables
A testing and development tool for temporarily injecting environment variables.
Installation
pip install inject-environment-variables
Usage
Variables can be injected into the environment via either a with statement or a decorator.
With statement
Variables specified in the EnvironmentVariableInjector.
When the with exits the environment (os.environ) will be reset to how it was when the statement enters.
Meaning any changes to the environment during the statement will be lost.
import os
from inject_environment_variables import EnvironmentVariableInjector
with EnvironmentVariableInjector({
'VARIABLE_1': 'foo',
'VARIABLE_2': 'bar'
}):
print(os.getenv('VARIABLE_1'))
Decorator
Variables can be specified by decorating a function with the inject_environment_variables decorator.
These changes to the environment are only active for the duration of the decorated function. At the end of the function the environment will be reset to how it was when the function started, meaning any changes to the environment during the statement will be lost.
import os
from inject_environment_variables.decorator import inject_environment_variables
@inject_environment_variables({
'VARIABLE_1': 'foo',
'VARIABLE_2': 'bar'
})
def test_environment_variables():
print(os.getenv('VARIABLE_1'))
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 inject_environment_variables-1.0.1.tar.gz.
File metadata
- Download URL: inject_environment_variables-1.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fd271d78849737cc1be59eb3c27515f44a12b29755135ea0f7fc183c77520b3
|
|
| MD5 |
cfe602a214a035a42583c2e332d13084
|
|
| BLAKE2b-256 |
0cc1384d874963195dbe12d5c94f381c57892c288587b69d6729d62162bc624c
|
File details
Details for the file inject_environment_variables-1.0.1-py3-none-any.whl.
File metadata
- Download URL: inject_environment_variables-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
449637894d3ce60b62ea447881716a304657f69b96f9de1ca178b1316853c6d5
|
|
| MD5 |
33c3bab4afff35b23b53835352d26489
|
|
| BLAKE2b-256 |
15215551ebe3bb89a6f13d3f32c4d1d88f6c8749263eab959f3782e51c52b270
|