Skip to content

✨ feat(plugin): add .env file loading support#191

Merged
gaborbernat merged 1 commit intopytest-dev:mainfrom
gaborbernat:184
Feb 11, 2026
Merged

✨ feat(plugin): add .env file loading support#191
gaborbernat merged 1 commit intopytest-dev:mainfrom
gaborbernat:184

Conversation

@gaborbernat
Copy link
Collaborator

The pytest-dotenv plugin is no longer maintained, leaving users without
a supported way to load .env files during test runs. This adds native .env file support directly to pytest-env,
so users can drop the extra dependency and keep their workflow intact. Closes #184.

A new env_files config option accepts a list of .env file paths, resolved relative to the project root. 📂 The
parser handles KEY=VALUE lines, # comments, blank lines, optional single/double quoting, and whitespace around
keys and values. Missing files are silently skipped, following the dotenv convention that allows committing config
referencing .env while the file only exists locally.

.env files are loaded before inline env entries, so inline config always takes precedence. ✨ This means
existing flags like skip_if_set and transform work naturally with values loaded from .env files. The feature
works across all config formats — native TOML (env_files = [".env"]), and INI linelist (env_files = .env).

@gaborbernat gaborbernat force-pushed the 184 branch 5 times, most recently from bb1dd49 to a87802c Compare February 11, 2026 17:33
Replaces the unmaintained pytest-dotenv by adding native .env file
support. Files are loaded before inline env entries so that inline
config can override .env values.

Configured via env_files in TOML native format or INI linelist.
Parses KEY=VALUE lines, skips comments and blank lines, strips
optional quotes. Missing files are silently ignored.

Closes pytest-dev#184

Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
@gaborbernat gaborbernat merged commit cd5d78c into pytest-dev:main Feb 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support to pass dot env file

1 participant