pytest plugin that allows you to add environment variables.
Project description
pytest-env
This is a pytest
plugin that enables you to set environment variables in a pytest.ini
or pyproject.toml
file.
Installation
Install with pip:
pip install pytest-env
Usage
Native form in pyproject.toml
[tool.pytest_env]
HOME = "~/tmp"
RUN_ENV = 1
TRANSFORMED = {value = "{USER}/alpha", transform = true}
SKIP_IF_SET = {value = "on", skip_if_set = true}
The tool.pytest_env
tables keys are the environment variables keys to set. The right hand side of the assignment:
- if an inline table you can set options via the
transform
orskip_if_set
keys, while thevalue
key holds the value to set (or transform before setting). For transformation the variables you can use is other environment variable, - otherwise the value to set for the environment variable to set (casted to a string).
Via pytest configurations
In your pytest.ini file add a key value pair with env
as the key and the environment variables as a line separated
list of KEY=VALUE
entries. The defined variables will be added to the environment before any tests are run:
[pytest]
env =
HOME=~/tmp
RUN_ENV=test
Or with pyproject.toml
:
[tool.pytest.ini_options]
env = [
"HOME=~/tmp",
"RUN_ENV=test",
]
Only set if not already set
You can use D:
(default) as prefix if you don't want to override existing environment variables:
[pytest]
env =
D:HOME=~/tmp
D:RUN_ENV=test
Transformation
You can use existing environment variables using a python-like format, these environment variables will be expended before setting the environment variable:
[pytest]
env =
RUN_PATH=/run/path/{USER}
You can apply the R:
prefix to keep the raw value and skip this transformation step (can combine with the D:
flag,
order is not important):
[pytest]
env =
R:RUN_PATH=/run/path/{USER}
R:D:RUN_PATH_IF_NOT_SET=/run/path/{USER}
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 pytest_env-1.1.5.tar.gz
.
File metadata
- Download URL: pytest_env-1.1.5.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91209840aa0e43385073ac464a554ad2947cc2fd663a9debf88d03b01e0cc1cf |
|
MD5 | ada293c887a106227d2bbe46aec83b0a |
|
BLAKE2b-256 | 1f3127f28431a16b83cab7a636dce59cf397517807d247caa38ee67d65e71ef8 |
File details
Details for the file pytest_env-1.1.5-py3-none-any.whl
.
File metadata
- Download URL: pytest_env-1.1.5-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce90cf8772878515c24b31cd97c7fa1f4481cd68d588419fd45f10ecaee6bc30 |
|
MD5 | 5b6016b3f911af773af44c233882acdf |
|
BLAKE2b-256 | deb887cfb16045c9d4092cfcf526135d73b88101aac83bc1adcf82dfb5fd3833 |