pytest-dotenv
A py.test plugin that parses environment files before running tests
What it is and what it does
pytest-dotenv is a pytest plugin that integrates python-dotenv to automatically load environment variables from .env files before tests run. It detects .env files in the working directory or ancestor directories and populates os.environ without overriding existing system variables by default. The plugin supports multiple configuration files (e.g., .env, .test.env, .deploy.env) defined in pytest config files like pytest.ini or tox.ini, and can be controlled via command-line flags.
The package depends on pytest and python-dotenv as its only runtime dependencies, making installation lightweight. However, it is archived and abandoned—the last release was in June 2020, and there have been no updates since. While it remains popular (top 5000 packages), the lack of maintenance means it may not be compatible with recent pytest or Python versions, and security or compatibility issues will not be addressed.
Use it for:
- Load test-specific environment variables from .env files without modifying system environment during CI/CD pipelines
- Manage multiple environment configurations (.env, .test.env, .deploy.env) for different test scenarios
- Automatically populate pytest fixtures or test code with environment-based configuration without manual setup
- Override environment variables selectively during test runs while preserving production settings in the base environment
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that automatically loads environment variables from .env files before test runs, with support for multiple files and optional override of existing system variables.
No—not for new projects. The package is archived and abandoned since 2020, with no maintenance or security updates. While it may still work with older pytest and Python versions, there is significant risk of incompatibility with modern tooling. Consider using python-dotenv directly in your test fixtures or conftest.py, or look for actively maintained alternatives that provide the same functionality.
Install
pytest-dotenv on PyPI
pip
pip install pytest-dotenvuv
uv add pytest-dotenvpoetry
poetry add pytest-dotenvInstalling pytest-dotenv
Before you install
Installation is straightforward with low friction. However, the package is archived and abandoned—the last release was in 2020, over 2250 days ago. While it has maintained a stable position in the top 5000 PyPI packages, no active maintenance means security updates or compatibility fixes are unlikely.
License in practice
Licensed under MIT (permissive), so there are no restrictions on commercial or private use, modification, or redistribution.
Quickstart
pip install pytest-dotenv
# In pytest.ini or tox.ini:
[pytest]
env_files = .env
# Or run: pytest --envfile .env
Requires pytest and python-dotenv as runtime dependencies; no known system-level blockers.
Verify before relying
- Whether the package remains compatible with pytest versions released after 2020
- Whether python-dotenv's API changes since 2020 affect this plugin's functionality
- Active community forks or maintained alternatives that provide the same functionality
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pytest, python-dotenv |
| Maintenance | abandoned — 2,250 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 5,523,005/month — #2,082 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_dotenv-0.5.2-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-envA pytest plugin that loads environment…
permissive · top 1,000 on PyPI
pytest-pythonpathAdds directories to Python's import path before…
permissive · top 15,000 on PyPI
poetry-dotenv-pluginA Poetry plugin that automatically loads…
permissive · top 15,000 on PyPI
python-dotenvReads key-value pairs from a .env file and sets…
permissive · top 100 on PyPI
dotenvLoads environment variables from a .env file…
unclear · top 5,000 on PyPI
load-dotenvAutomatically loads environment variables from…
permissive · top 15,000 on PyPI
django-dotenvLoads environment variables from a .env file…
permissive · top 15,000 on PyPI
environ-configLoads application configuration from…
permissive · top 15,000 on PyPI
everettEverett is a configuration library that reads…
copyleft · top 15,000 on PyPI
dump-envGenerates .env files by merging an…
permissive · top 15,000 on PyPI