Skip to main content

py.test plugin that allows you to add environment variables.

Project description

pytest-env

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.

Installation

Install with pip:

pip install pytest-env

Usage

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.0.0.tar.gz (7.5 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.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_env-1.0.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pytest_env-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3265fe88f570337635689bacd9dafbe6e227c524abdb2b0f46454d6b6011a51c
MD5 45901b56d62402b5629345468dd2cd8e
BLAKE2b-256 f53034398641fe243c2d69d1cd1ef2d8d607843c7d93182383c3c301c20bc2e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_env-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pytest_env-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5ec593abf2430e21aec5b62ef50a0d894de634e84c935a44f3fe9663c5868c6
MD5 0d07e909cac17f69864ead6f653c0b6d
BLAKE2b-256 4b5c8d5eef48c66a092c68590c79d4d366eb9120a8c7b1d643d3bab1fee704cc

See more details on using hashes here.

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