Skip to main content

pytest plugin that allows you to add environment variables.

Project description


PyPI Supported Python versions check Code style: black Downloads

This is a pytest plugin that enables you to set environment variables in a pytest.ini or pyproject.toml file.


Install with pip:

pip install pytest-env


Native form in pyproject.toml

HOME = "~/tmp"
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 hands-ide of the assigment:

  • if an inline table you can set options via the transform or skip_if_set keys, while the value 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:

env =

Or with pyproject.toml:

env = [

Only set if not already set

You can use D: (default) as prefix if you don't want to override existing environment variables:

env =


You can use existing environment variables using a python-like format, these environment variables will be expended before setting the environment variable:

env =

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):

env =

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_env-1.1.2.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

pytest_env-1.1.2-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page