Skip to content

✨ feat(cli): add --envfile option for runtime environment switching#197

Merged
gaborbernat merged 1 commit intopytest-dev:mainfrom
gaborbernat:envfile-cli
Feb 17, 2026
Merged

✨ feat(cli): add --envfile option for runtime environment switching#197
gaborbernat merged 1 commit intopytest-dev:mainfrom
gaborbernat:envfile-cli

Conversation

@gaborbernat
Copy link
Collaborator

@gaborbernat gaborbernat commented Feb 17, 2026

Developers testing against different environments (dev, staging, prod) had to modify config files or maintain separate configuration files for each environment. This became cumbersome when switching contexts frequently, and risky when accidentally committing local overrides. 🔧

The --envfile CLI argument provides runtime control over environment files with two modes. Override mode (--envfile PATH) replaces all configured env_files, while extend mode (--envfile +PATH) adds to them. The CLI file loads last in extend mode, ensuring its variables take precedence over config files. Unlike config-based env_files which silently skip missing files, CLI-specified files must exist, failing fast on typos or incorrect paths.

The README has been restructured following the Diátaxis framework to improve navigation. 📚 The new organization separates tutorial content (quick start), task-focused how-to guides, complete reference documentation, and conceptual explanations. This helps users find what they need based on their goal rather than hunting through a single long document.

Fixes #196

@gaborbernat gaborbernat force-pushed the envfile-cli branch 2 times, most recently from 53764a0 to c016e68 Compare February 17, 2026 15:30
@gaborbernat gaborbernat enabled auto-merge (squash) February 17, 2026 15:30
@gaborbernat gaborbernat disabled auto-merge February 17, 2026 15:30
Users needed a way to switch between different environment configurations
without modifying config files. This is particularly useful when testing
against different environments (dev, staging, prod) or when developers
need local overrides without changing version-controlled configuration.

Implemented a --envfile CLI argument with two modes. Override mode
(--envfile PATH) replaces all configured env_files, while extend mode
(--envfile +PATH) adds to them. The CLI file always loads last in extend
mode, ensuring its variables take precedence. Unlike config-based env_files
which silently skip missing files, CLI files must exist to fail fast on
typos or incorrect paths.

Restructured README following Diátaxis framework to separate tutorial
content (quick start), how-to guides (task-focused), reference (complete
API), and explanation (conceptual understanding). This makes the
documentation more navigable and helps users find what they need based
on their goal.

Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
@gaborbernat gaborbernat merged commit ded63b0 into pytest-dev:main Feb 17, 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.

Feature request: support --envfile cli arg to dynamically add .env file

1 participant

Comments