Skip to content

Reject non-regular env files before rootdir fallback - #368

Closed
mk78 wants to merge 1 commit into
pytest-dev:mainfrom
mk78:mk78-pytest-env-small-defect
Closed

mk78 wants to merge 1 commit into
pytest-dev:mainfrom
mk78:mk78-pytest-env-small-defect

Conversation

@mk78

@mk78 mk78 commented Dec 3, 2026

Copy link
Copy Markdown

Summary

Fix environment-file resolution when an invocation-directory candidate exists but is not a regular file.

Previously, pytest-env searched all candidates for regular files before checking for invalid paths. This allowed a valid rootdir file to override an invalid, higher-priority invocation-directory path.

Candidates are now validated sequentially in precedence order. An existing non-regular path produces the established pytest usage error instead of silently falling back.

Tests

  • Regression test fails on unmodified main and passes with fix
  • Full suite: 195 passed, 1 skipped
  • Coverage: 100%
  • Python 3.11–3.15: passed
  • Pre-commit: passed
  • Linux typing checks: passed

The existing Windows-only os.mkfifo typing diagnostic is unchanged from upstream.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@mk78
mk78 requested a review from gaborbernat as a code owner December 3, 2026 11:19
@gaborbernat

Copy link
Copy Markdown
Collaborator

Thanks for the PR. The current order is deliberate: #356 made --envfile look for a regular file among both candidates first and raise only when none qualifies. Stopping at the first existing path would turn a working layout into an error, for example a .env virtual environment in the folder pytest runs from, below a rootdir that holds the project's .env file.

@gaborbernat gaborbernat closed this Dec 4, 2026
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.

2 participants