You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test_shutil.test_environ_path_cwd fails when NoDefaultCurrentDirectoryInExePath is set #156376
test.test_shutil.TestWhich.test_environ_path_cwd and test.test_shutil.TestWhichBytes.test_environ_path_cwd fail on Windows when the
environment variable NoDefaultCurrentDirectoryInExePath is set in the
environment the test suite runs in:
The test asserts that shutil.which() finds the file in the current directory,
expecting a .\-prefixed result on Windows. However, shutil.which() only
inserts the current directory into the search path when _win_path_needs_curdir() returns true (Lib/shutil.py), and that delegates to _winapi.NeedCurrentDirectoryForExePath(). The underlying NeedCurrentDirectoryForExePathW() API consults NoDefaultCurrentDirectoryInExePath, so when that variable is present the
current directory is not searched and the assertion fails.
The test does use os_helper.EnvironmentVarGuard, but only to set PATH; it
does not neutralise NoDefaultCurrentDirectoryInExePath, so an ambient value
leaks into the test. TestWhich.test_win_path_needs_curdir in the same file
already accounts for this mechanism by patching _winapi.NeedCurrentDirectoryForExePath.
Reproducer on Windows:
set NoDefaultCurrentDirectoryInExePath=1
python -m test test_shutil
Unsetting the variable inside the existing EnvironmentVarGuard makes the test
independent of the ambient environment. I have a fix and will open a PR.
Activity