Skip to main content

pytest plugin that allows you to add environment variables.

Project description

pytest-env

PyPI Supported Python versions check Downloads

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

[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


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.2.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_env-1.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_env-1.2.0.tar.gz.

File metadata

  • Download URL: pytest_env-1.2.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_env-1.2.0.tar.gz
Algorithm Hash digest
SHA256 475e2ebe8626cee01f491f304a74b12137742397d6c784ea4bc258f069232b80
MD5 6c753b48d8e61eaedc6f9ae3f43117d5
BLAKE2b-256 13129c87d0ca45d5992473208bcef2828169fa7d39b8d7fc6e3401f5c08b8bf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_env-1.2.0.tar.gz:

Publisher: release.yaml on pytest-dev/pytest-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_env-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_env-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_env-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7e5b7198f9b83c795377c09feefa45d56083834e60d04767efd64819fc9da00
MD5 e9abd1e5c7c10e18c73c9abe2c5ce7cd
BLAKE2b-256 2798822b924a4a3eb58aacba84444c7439fce32680592f394de26af9c76e2569

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_env-1.2.0-py3-none-any.whl:

Publisher: release.yaml on pytest-dev/pytest-env

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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