A py.test plugin that parses environment files before running tests
Project description
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
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-dotenv-0.5.2.tar.gz
.
File metadata
- Download URL: pytest-dotenv-0.5.2.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dc6c3ac6d8764c71c6d2804e902d0ff810fa19692e95fe138aefc9b1aa73732 |
|
MD5 | bd8574925d1bf999824f01d04fffe292 |
|
BLAKE2b-256 | cdb0cafee9c627c1bae228eb07c9977f679b3a7cb111b488307ab9594ba9e4da |
File details
Details for the file pytest_dotenv-0.5.2-py3-none-any.whl
.
File metadata
- Download URL: pytest_dotenv-0.5.2-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a2cece120a213898afaa5407673f6bd924b1fa7eafce6bda0e8abffe2f710f |
|
MD5 | a10058f649421d79ed37f6d3eb137f78 |
|
BLAKE2b-256 | d0da9da67c67b3d0963160e3d2cbc7c38b6fae342670cc8e6d5936644b2cf944 |