Skip to content

✨ feat(plugin): add --pytest-env-verbose for debugging env assignments#199

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

✨ feat(plugin): add --pytest-env-verbose for debugging env assignments#199
gaborbernat merged 1 commit intopytest-dev:mainfrom
gaborbernat:198

Conversation

@gaborbernat
Copy link
Collaborator

@gaborbernat gaborbernat commented Feb 17, 2026

When multiple env files, inline config, CLI --envfile options, and exported variables all interact, tracking what pytest-env actually sets becomes painful. This is especially true after the recent addition of .env file loading and the --envfile CLI option, which significantly increased the number of possible sources. Closes #198.

The new --pytest-env-verbose flag prints every environment variable action (SET, SKIP, UNSET) along with its source file in the test session header via pytest_report_header, following the same pattern pytest's own cacheprovider uses. This avoids the get_terminal_writer() assertion error that occurs during early hooks and integrates cleanly with pytest's output capturing.

Example run with a pyproject.toml config, a .env file, and TEMP_VAR exported in the shell:

$ pytest --pytest-env-verbose
============================= test session starts ==============================
platform darwin -- Python 3.14.3, pytest-9.0.2, pluggy-1.6.0
pytest-env:
  SET   API_KEY=secret123  (from /project/.env)
  SET   DEBUG=true  (from /project/.env)
  SET   DATABASE_URL=postgres://localhost/test  (from /project/pyproject.toml)
  SKIP  HOME=/Users/me  (from /project/pyproject.toml)
  UNSET TEMP_VAR  (from /project/pyproject.toml)
rootdir: /project
configfile: pyproject.toml
collected 1 item

test_it.py .                                                             [100%]
============================== 1 passed in 0.01s ===============================

This PR also replaces prettier with mdformat (with mdformat-toc, mdformat-gfm, and mdformat-config plugins) and yamlfmt in pre-commit, and restructures the README for readability within the existing Diataxis layout -- grouping CLI options together, consolidating small how-to guides, and adding an auto-generated table of contents.

When multiple env files, inline config, and CLI options interact it
becomes hard to track which values pytest-env actually sets. The new
flag prints each action (SET, SKIP, UNSET) with source file in the
session header via pytest_report_header, following pytest conventions.

Also replaces prettier with mdformat (+ toc/gfm/config plugins) and
yamlfmt in pre-commit, and restructures the README for readability
while keeping the Diataxis layout.
@gaborbernat gaborbernat enabled auto-merge (squash) February 17, 2026 18:30
@gaborbernat gaborbernat disabled auto-merge February 17, 2026 18:30
@gaborbernat gaborbernat merged commit 28a0c11 into pytest-dev:main Feb 17, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: verbose mode

1 participant

Comments