FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-156376: Make test_environ_path_cwd independent of the ambient environment by KindPinningFinalBoss · Pull Request #156377 · python/cpython · GitHub

/ cpython Public

gh-156376: Make test_environ_path_cwd independent of the ambient environment - #156377

Open
KindPinningFinalBoss wants to merge 1 commit into
python:mainfrom
KindPinningFinalBoss:fix-test-shutil-curdir-env
Open

gh-156376: Make test_environ_path_cwd independent of the ambient environment#156377
KindPinningFinalBoss wants to merge 1 commit into
python:mainfrom
KindPinningFinalBoss:fix-test-shutil-curdir-env

Conversation

KindPinningFinalBoss commented Aug 25, 2026
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown

TestWhich.test_environ_path_cwd and TestWhichBytes.test_environ_path_cwd
fail on Windows when NoDefaultCurrentDirectoryInExePath is set in the
environment the test suite runs in.

The test clears PATH so that shutil.which() falls back to the current
directory, then asserts the result is .\<file>. But shutil.which() only
inserts the current directory into the search path when
_win_path_needs_curdir() returns true, which delegates to
_winapi.NeedCurrentDirectoryForExePath(). That API consults
NoDefaultCurrentDirectoryInExePath, so when the variable is present
which() correctly declines to search the current directory and the
assertion fails.

The test already opens an os_helper.EnvironmentVarGuard to set PATH;
this unsets NoDefaultCurrentDirectoryInExePath in the same guard so the
ambient environment cannot change what the test exercises.
TestWhich.test_win_path_needs_curdir in the same class already accounts
for this mechanism by patching _winapi.NeedCurrentDirectoryForExePath.

Verified on Windows 11, main at 04242c0:

scenario before after
variable set 2 failures passes
variable unset passes passes

No behaviour change to shutil; test-only.

…t environment

shutil.which() only inserts the current directory into the search path when
_winapi.NeedCurrentDirectoryForExePath() returns true, and that consults the
NoDefaultCurrentDirectoryInExePath environment variable. On a machine where
that variable is set, TestWhich.test_environ_path_cwd and
TestWhichBytes.test_environ_path_cwd failed because which() correctly
declined to search the current directory.

Unset the variable inside the EnvironmentVarGuard the test already uses, so
an ambient value cannot change what the test exercises.
bedevere-app Bot added the tests Tests in the Lib/test dir label Aug 25, 2026

bedevere-app Bot commented Aug 25, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL