pytest-env


Namepytest-env JSON
Version 1.1.3 PyPI version JSON
download
home_page
Summarypytest plugin that allows you to add environment variables.
upload_time2023-11-28 04:11:27
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2010-202x The pytest-env developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords env pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-env

[![PyPI](https://img.shields.io/pypi/v/pytest-env?style=flat-square)](https://pypi.org/project/pytest-env/)
[![Supported Python
versions](https://img.shields.io/pypi/pyversions/pytest-env.svg)](https://pypi.org/project/pytest-env/)
[![check](https://github.com/pytest-dev/pytest-env/actions/workflows/check.yml/badge.svg)](https://github.com/pytest-dev/pytest-env/actions/workflows/check.yml)
[![Code style:
black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Downloads](https://static.pepy.tech/badge/pytest-env/month)](https://pepy.tech/project/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:

```shell
pip install pytest-env
```

## Usage

### Native form in `pyproject.toml`

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

```ini
[pytest]
env =
    HOME=~/tmp
    RUN_ENV=test
```

Or with `pyproject.toml`:

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

```ini
[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:

```ini
[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):

```ini
[pytest]
env =
    R:RUN_PATH=/run/path/{USER}
    R:D:RUN_PATH_IF_NOT_SET=/run/path/{USER}
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pytest-env",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Bern\u00e1t G\u00e1bor <gaborjbernat@gmail.com>",
    "keywords": "env,pytest",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/02/cc/df6940b2527bfa634c00940dfb6e3ec873bdfb7507b55894c93283fa3178/pytest_env-1.1.3.tar.gz",
    "platform": null,
    "description": "# pytest-env\n\n[![PyPI](https://img.shields.io/pypi/v/pytest-env?style=flat-square)](https://pypi.org/project/pytest-env/)\n[![Supported Python\nversions](https://img.shields.io/pypi/pyversions/pytest-env.svg)](https://pypi.org/project/pytest-env/)\n[![check](https://github.com/pytest-dev/pytest-env/actions/workflows/check.yml/badge.svg)](https://github.com/pytest-dev/pytest-env/actions/workflows/check.yml)\n[![Code style:\nblack](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Downloads](https://static.pepy.tech/badge/pytest-env/month)](https://pepy.tech/project/pytest-env)\n\nThis is a `pytest` plugin that enables you to set environment variables in a `pytest.ini` or `pyproject.toml` file.\n\n## Installation\n\nInstall with pip:\n\n```shell\npip install pytest-env\n```\n\n## Usage\n\n### Native form in `pyproject.toml`\n\n```toml\n[tool.pytest_env]\nHOME = \"~/tmp\"\nRUN_ENV = 1\nTRANSFORMED = {value = \"{USER}/alpha\", transform = true}\nSKIP_IF_SET = {value = \"on\", skip_if_set = true}\n```\n\nThe `tool.pytest_env` tables keys are the environment variables keys to set. The right hands-ide of the assigment:\n\n- if an inline table you can set options via the `transform` or `skip_if_set` keys, while the `value` key holds the\n  value to set (or transform before setting). For transformation the variables you can use is other environment\n  variable,\n- otherwise the value to set for the environment variable to set (casted to a string).\n\n### Via pytest configurations\n\nIn your pytest.ini file add a key value pair with `env` as the key and the environment variables as a line separated\nlist of `KEY=VALUE` entries. The defined variables will be added to the environment before any tests are run:\n\n```ini\n[pytest]\nenv =\n    HOME=~/tmp\n    RUN_ENV=test\n```\n\nOr with `pyproject.toml`:\n\n```toml\n[tool.pytest.ini_options]\nenv = [\n    \"HOME=~/tmp\",\n    \"RUN_ENV=test\",\n]\n```\n\n### Only set if not already set\n\nYou can use `D:` (default) as prefix if you don't want to override existing environment variables:\n\n```ini\n[pytest]\nenv =\n    D:HOME=~/tmp\n    D:RUN_ENV=test\n```\n\n### Transformation\n\nYou can use existing environment variables using a python-like format, these environment variables will be expended\nbefore setting the environment variable:\n\n```ini\n[pytest]\nenv =\n    RUN_PATH=/run/path/{USER}\n```\n\nYou can apply the `R:` prefix to keep the raw value and skip this transformation step (can combine with the `D:` flag,\norder is not important):\n\n```ini\n[pytest]\nenv =\n    R:RUN_PATH=/run/path/{USER}\n    R:D:RUN_PATH_IF_NOT_SET=/run/path/{USER}\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2010-202x The pytest-env developers  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "pytest plugin that allows you to add environment variables.",
    "version": "1.1.3",
    "project_urls": {
        "Homepage": "https://github.com/pytest-dev/pytest-env",
        "Source": "https://github.com/pytest-dev/pytest-env",
        "Tracker": "https://github.com/pytest-dev/pytest-env/issues"
    },
    "split_keywords": [
        "env",
        "pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25b2bdc663a5647ce2034f7e8420122af340df87c01ba97745fc753b8c917acb",
                "md5": "1862074a0c634216361579d0247b9042",
                "sha256": "aada77e6d09fcfb04540a6e462c58533c37df35fa853da78707b17ec04d17dfc"
            },
            "downloads": -1,
            "filename": "pytest_env-1.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1862074a0c634216361579d0247b9042",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6154,
            "upload_time": "2023-11-28T04:11:25",
            "upload_time_iso_8601": "2023-11-28T04:11:25.923114Z",
            "url": "https://files.pythonhosted.org/packages/25/b2/bdc663a5647ce2034f7e8420122af340df87c01ba97745fc753b8c917acb/pytest_env-1.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02ccdf6940b2527bfa634c00940dfb6e3ec873bdfb7507b55894c93283fa3178",
                "md5": "60eb1ac5a5b646a69f0e197103df61a6",
                "sha256": "fcd7dc23bb71efd3d35632bde1bbe5ee8c8dc4489d6617fb010674880d96216b"
            },
            "downloads": -1,
            "filename": "pytest_env-1.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "60eb1ac5a5b646a69f0e197103df61a6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8627,
            "upload_time": "2023-11-28T04:11:27",
            "upload_time_iso_8601": "2023-11-28T04:11:27.607034Z",
            "url": "https://files.pythonhosted.org/packages/02/cc/df6940b2527bfa634c00940dfb6e3ec873bdfb7507b55894c93283fa3178/pytest_env-1.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-28 04:11:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytest-dev",
    "github_project": "pytest-env",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-env"
}
        
Elapsed time: 0.16948s