diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index c0b48ea306b71ed..783fe1868249148 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -2729,7 +2729,9 @@ def test_environ_path_cwd(self): self.assertIsNone(rv) # look in current directory - with os_helper.change_cwd(self.dir): + with os_helper.change_cwd(self.dir), \ + unittest.mock.patch('shutil._win_path_needs_curdir', + return_value=True): rv = shutil.which(self.file) self.assertEqual(rv, expected_cwd) diff --git a/Misc/NEWS.d/next/Tests/2026-11-03-22-45-00.gh-issue-156376.Wq7rKe.rst b/Misc/NEWS.d/next/Tests/2026-11-03-22-45-00.gh-issue-156376.Wq7rKe.rst new file mode 100644 index 000000000000000..73bb4f482df29cb --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-11-03-22-45-00.gh-issue-156376.Wq7rKe.rst @@ -0,0 +1,3 @@ +Fix ``test_shutil.test_environ_path_cwd`` on Windows, which relied on the +user's ``NoDefaultCurrentDirectoryInExePath`` environment setting and was +therefore non-deterministic.