⚡ Sangsakala Proxy 🏠 Home
Skip to content

gh-156376: Fix test_environ_path_cwd when NoDefaultCurrentDirectoryInExePath is set - #161277

Open
ArtyomSimitian wants to merge 2 commits into
python:mainfrom
ArtyomSimitian:gh-156376-which-nodefaultcurdir
Open

ArtyomSimitian wants to merge 2 commits into
python:mainfrom
ArtyomSimitian:gh-156376-which-nodefaultcurdir

Conversation

@ArtyomSimitian

@ArtyomSimitian ArtyomSimitian commented Nov 3, 2026 •

Copy link
Copy Markdown

test_shutil.test_environ_path_cwd on Windows relied on the user's
NoDefaultCurrentDirectoryInExePath environment setting and was therefore
non-deterministic. When that variable is set, Windows skips searching the
current directory, so shutil.which() returned 'file.exe' instead of the
expected '.\\file.exe' and the test failed.

This change mocks shutil._win_path_needs_curdir to return True for the
part of the test that expects the current-directory lookup, so the result no
longer depends on the machine's settings. test_cwd_win32 already uses the
same approach. On non-Windows platforms which() never calls that function,
so behavior there is unchanged.

Tested on Windows 11 (debug build):

  • With NoDefaultCurrentDirectoryInExePath=1: before the fix,
    test_environ_path_cwd failed in both TestWhich and TestWhichBytes.
    After the fix, all 54 which tests pass (2 skipped as non-win32).
  • Without the variable: all 54 which tests pass.
  • Full test_shutil: 238 run, 0 failures.

No other which tests were affected by the variable.

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