Skip to main content

pytest-dotenv

This little plugin uses python-dotenv to load any environment variables from a .env file. Extra configuration can be defined in any pytest config files, such as pytest.ini, tox.ini and so on.

Installation

Install the plugin with pip:

$ pip install pytest-dotenv

Basic Usage

If all you want is to load environment variables from a .env file then installing the plugin is all that is needed. python-dotenv will automatically detect your .env file and load it. By default, the plugin won't override any existing system variables.

Non-default configuration

Custom Environment Variable Files

Add a new section to a config file named env_vars. You can list as many files as necessary:

[pytest]
env_files =
    .env
    .test.env
    .deploy.env

The files will be loaded and added to the os.environ dict object before any tests are run. If the files are not found on the working directory, it will search for the files in the ancestor directory and upwards.

Overriding Existing Values

By default the plugin will not override any variables already defined in the process' environment. If you want that behavior, you have to use the env_override_existing_values setting:

[pytest]
env_override_existing_values = 1
env_files =
    .env
    .test.env
    .deploy.env

Alternative: Specify the file at the command line

You also have the option to run your tests with py.test --envfile path/to/.env. This will load all defined environment variables and overwrite any existing ones regardless of the configuration env_override_existing_values.

Release files for pytest-dotenv 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-dotenv 0.5.2
File Size Uploaded
pytest-dotenv-0.5.2.tar.gz 3.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-dotenv 0.5.2
File Interpreter ABI Platform
pytest_dotenv-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / pytest-dotenv-0.5.2.tar.gz

Download URL pytest-dotenv-0.5.2.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2dc6c3ac6d8764c71c6d2804e902d0ff810fa19692e95fe138aefc9b1aa73732
BLAKE2b-256 checksum
How to use checksums
cdb0cafee9c627c1bae228eb07c9977f679b3a7cb111b488307ab9594ba9e4da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

Release files / pytest_dotenv-0.5.2-py3-none-any.whl

Download URL pytest_dotenv-0.5.2-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40a2cece120a213898afaa5407673f6bd924b1fa7eafce6bda0e8abffe2f710f
BLAKE2b-256 checksum
How to use checksums
d0da9da67c67b3d0963160e3d2cbc7c38b6fae342670cc8e6d5936644b2cf944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page