Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quiqua/pytest-dotenv
A py.test plugin that parses environment files before running tests
https://github.com/quiqua/pytest-dotenv
Last synced: 29 days ago
JSON representation
A py.test plugin that parses environment files before running tests
- Host: GitHub
- URL: https://github.com/quiqua/pytest-dotenv
- Owner: quiqua
- License: mit
- Created: 2016-06-07T13:25:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-05T18:11:32.000Z (about 1 year ago)
- Last Synced: 2024-04-28T20:03:46.253Z (8 months ago)
- Language: Python
- Homepage:
- Size: 30.3 KB
- Stars: 176
- Watchers: 2
- Forks: 18
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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`:
```sh
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 named `env_files` to your pytest config file.
You can list as many files as necessary:```ini
[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:```ini
[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`.